nb diff perf improvements by comparing hash values (#227145)

* nb diff perf improvements by comparing hash values

* More efficient
pull/227144/head
Don Jayamanne 2024-08-30 06:28:13 +10:00 committed by GitHub
parent f6d9f0edf5
commit e674b3a0b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 4 deletions

View File

@ -1644,7 +1644,7 @@ export class ModifiedElement extends AbstractElementRenderer {
{
updateInfoRendering: () => renderSourceEditor(),
checkIfModified: (cell) => {
return cell.modified?.textModel.getValue() !== cell.original?.textModel.getValue() ? { reason: undefined } : false;
return cell.modified?.textModel.getTextBufferHash() !== cell.original?.textModel.getTextBufferHash() ? { reason: undefined } : false;
},
getFoldingState: (cell) => cell.cellFoldingState,
updateFoldingState: (cell, state) => cell.cellFoldingState = state,
@ -1660,7 +1660,7 @@ export class ModifiedElement extends AbstractElementRenderer {
const scopedContextKeyService = this.contextKeyService.createScoped(this.templateData.inputToolbarContainer);
this._register(scopedContextKeyService);
const inputChanged = NOTEBOOK_DIFF_CELL_INPUT.bindTo(scopedContextKeyService);
inputChanged.set(this.cell.modified.textModel.getValue() !== this.cell.original.textModel.getValue());
inputChanged.set(this.cell.modified.textModel.getTextBufferHash() !== this.cell.original.textModel.getTextBufferHash());
const ignoreWhitespace = NOTEBOOK_DIFF_CELL_IGNORE_WHITESPACE.bindTo(scopedContextKeyService);
const ignore = this.textConfigurationService.getValue<boolean>(this.cell.modified.uri, 'diffEditor.ignoreTrimWhitespace');
@ -1675,7 +1675,7 @@ export class ModifiedElement extends AbstractElementRenderer {
const refreshToolbar = () => {
const ignore = this.textConfigurationService.getValue<boolean>(this.cell.modified.uri, 'diffEditor.ignoreTrimWhitespace');
ignoreWhitespace.set(ignore);
const hasChanges = this.cell.modified.textModel.getValue() !== this.cell.original.textModel.getValue();
const hasChanges = this.cell.modified.textModel.getTextBufferHash() !== this.cell.original.textModel.getTextBufferHash();
inputChanged.set(hasChanges);
if (hasChanges) {

View File

@ -443,7 +443,7 @@ function createDiffViewModels(instantiationService: IInstantiationService, confi
case 'unchanged': {
const originalCell = originalModel.cells[diff.originalCellIndex];
const modifiedCell = modifiedModel.cells[diff.modifiedCellIndex];
const type = (originalCell.textModel?.getValue() !== modifiedCell.textModel?.getValue()) ? 'modified' : 'unchanged';
const type = originalCell.equal(modifiedCell) ? 'unchanged' : 'modified';
return new SideBySideDiffElementViewModel(
model.modified.notebook,
model.original.notebook,

View File

@ -419,6 +419,10 @@ export class NotebookCellTextModel extends Disposable implements ICell {
return false;
}
if (this.outputs.length !== b.outputs.length) {
return false;
}
if (this.getTextLength() !== b.getTextLength()) {
return false;
}