Skip to content

Conversation

rebornix
Copy link
Member

@rebornix rebornix commented Dec 9, 2020

This PR fixes #109680. It consists of following major changes:

  • Leverage the List view template to reuse the editors. This way we don't keep creating/removing code/diff editors while scrolling
  • Limit the editor contributions used the embedded diff editors.
  • Avoid unnecessary overview ruler rendering.

The diff editor is slower than the native notebook editor, simply because in the diff editor, the amount of monaco editors doubled. The creation and deletion of monaco editors has some cost, even if it's a few miliseconds, rendering 20 monaco editors in a large viewport can cost ~100ms. So the performance of scrolling in the diff editor is definitely slower than scrolling in a notebook editor with the same resource.

@rebornix rebornix self-assigned this Dec 9, 2020
Copy link

@rheh rheh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few points - mostly suggestions on removing duplication and improving readability. One question I cannot answer is do these changes require and changes to existing unit tests?

private _maxComputationTime: number;
private _renderIndicators: boolean;
private _enableSplitViewResizing: boolean;
private _wordWrap: 'off' | 'on' | 'wordWrapColumn' | 'bounded' | undefined;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would make sense to be of type enum

enum wordWrapEnum {
  Off,
  On,
  WordWrapColumn,
  Bounded
};
private _wordWrap: wordWrapEnum | null;

private _enableSplitViewResizing: boolean;
private _wordWrap: 'off' | 'on' | 'wordWrapColumn' | 'bounded' | undefined;
private _wordWrapMinified: boolean | undefined;
private _renderOverviewRuler: boolean;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As stated above these are not used? Is this intended?

this._contextKeyService.createKey('isInEmbeddedDiffEditor', false);
}

this._renderOverviewRuler = true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could roll this up into one-linear

this._renderOverviewRuler = typeof options.renderOverviewRuler !== 'undefined' ?  Boolean(options.renderOverviewRuler) : true;

this._isHandlingScrollEvent = false;

this._elementSizeObserver = this._register(new ElementSizeObserver(this._containerDomElement, undefined, () => this._onDidContainerSizeChanged()));
this._elementSizeObserver = this._register(new ElementSizeObserver(this._containerDomElement, options.dimension, () => this._onDidContainerSizeChanged()));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit-pick: arrow function not required:

this._elementSizeObserver = this._register(new ElementSizeObserver(this._containerDomElement, options.dimension, this._onDidContainerSizeChanged);

result.scrollbar!.verticalHasArrows = false;
result.extraEditorClassName = 'modified-in-monaco-diff-editor';
return result;
return {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of lines 1156 - 1162. One could add a private helper function e.g.

function addDimension(result) : editorBrowser.IEditorConstructionOptions {
return {
			...result,
			dimension: {
				height: 0,
				width: 0
			}
		};

Then call the helper from both places e.g.

return addDimension(result);

*/
isInEmbeddedEditor?: boolean;
/**
* Is the diff editor should render overview ruler
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a typo here: Is vs If?

readonly notebookEditor: INotebookTextDiffEditor,
readonly cell: CellDiffViewModel,
readonly templateData: CellDiffSingleSideRenderTemplate,
readonly style: 'left' | 'right' | 'full',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be an enum?

enum styleAlignments {
  Left,
  Right,
  Full
};

this._register(this._editor);
this._editor = this.templateData.sourceEditor;
this._editor.layout({
width: (this.notebookEditor.getLayoutInfo().width - 2 * DIFF_CELL_MARGIN) / 2 - 18,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 18 is a magic number. A named constant would help understand what this is for. That said, as if is a copy-paste then we can just skip adding the constant if you do not know.

buildBody() {
const body = this.templateData.body;
this._diffEditorContainer = this.templateData.diffEditorContainer;
switch (this.style) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This switch statement duplicated above. We could move this into a new function on the shared parent abstraction can call it from both places?

@rebornix rebornix merged commit 45283df into master Dec 10, 2020
@rebornix rebornix deleted the rebornix/nb-diff-perf branch December 10, 2020 01:52
@github-actions github-actions bot locked and limited conversation to collaborators Jan 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scrolling in a notebook diff editor is sluggish
2 participants