Skip to content

Commit e674b3a

Browse files
authored
nb diff perf improvements by comparing hash values (microsoft#227145)
* nb diff perf improvements by comparing hash values * More efficient
1 parent f6d9f0e commit e674b3a

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/vs/workbench/contrib/notebook/browser/diff/diffComponents.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ export class ModifiedElement extends AbstractElementRenderer {
16441644
{
16451645
updateInfoRendering: () => renderSourceEditor(),
16461646
checkIfModified: (cell) => {
1647-
return cell.modified?.textModel.getValue() !== cell.original?.textModel.getValue() ? { reason: undefined } : false;
1647+
return cell.modified?.textModel.getTextBufferHash() !== cell.original?.textModel.getTextBufferHash() ? { reason: undefined } : false;
16481648
},
16491649
getFoldingState: (cell) => cell.cellFoldingState,
16501650
updateFoldingState: (cell, state) => cell.cellFoldingState = state,
@@ -1660,7 +1660,7 @@ export class ModifiedElement extends AbstractElementRenderer {
16601660
const scopedContextKeyService = this.contextKeyService.createScoped(this.templateData.inputToolbarContainer);
16611661
this._register(scopedContextKeyService);
16621662
const inputChanged = NOTEBOOK_DIFF_CELL_INPUT.bindTo(scopedContextKeyService);
1663-
inputChanged.set(this.cell.modified.textModel.getValue() !== this.cell.original.textModel.getValue());
1663+
inputChanged.set(this.cell.modified.textModel.getTextBufferHash() !== this.cell.original.textModel.getTextBufferHash());
16641664

16651665
const ignoreWhitespace = NOTEBOOK_DIFF_CELL_IGNORE_WHITESPACE.bindTo(scopedContextKeyService);
16661666
const ignore = this.textConfigurationService.getValue<boolean>(this.cell.modified.uri, 'diffEditor.ignoreTrimWhitespace');
@@ -1675,7 +1675,7 @@ export class ModifiedElement extends AbstractElementRenderer {
16751675
const refreshToolbar = () => {
16761676
const ignore = this.textConfigurationService.getValue<boolean>(this.cell.modified.uri, 'diffEditor.ignoreTrimWhitespace');
16771677
ignoreWhitespace.set(ignore);
1678-
const hasChanges = this.cell.modified.textModel.getValue() !== this.cell.original.textModel.getValue();
1678+
const hasChanges = this.cell.modified.textModel.getTextBufferHash() !== this.cell.original.textModel.getTextBufferHash();
16791679
inputChanged.set(hasChanges);
16801680

16811681
if (hasChanges) {

src/vs/workbench/contrib/notebook/browser/diff/notebookDiffViewModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ function createDiffViewModels(instantiationService: IInstantiationService, confi
443443
case 'unchanged': {
444444
const originalCell = originalModel.cells[diff.originalCellIndex];
445445
const modifiedCell = modifiedModel.cells[diff.modifiedCellIndex];
446-
const type = (originalCell.textModel?.getValue() !== modifiedCell.textModel?.getValue()) ? 'modified' : 'unchanged';
446+
const type = originalCell.equal(modifiedCell) ? 'unchanged' : 'modified';
447447
return new SideBySideDiffElementViewModel(
448448
model.modified.notebook,
449449
model.original.notebook,

src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ export class NotebookCellTextModel extends Disposable implements ICell {
419419
return false;
420420
}
421421

422+
if (this.outputs.length !== b.outputs.length) {
423+
return false;
424+
}
425+
422426
if (this.getTextLength() !== b.getTextLength()) {
423427
return false;
424428
}

0 commit comments

Comments
 (0)