Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve problem view performance #12408

Merged
merged 3 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,16 @@ describe('problem-composite-tree-node', () => {
const lowMarkerNode = createMarkerInfo('2', new URI('b'), [lowNode]);

const highFirstRoot = getRootNode('highFirstRoot');
ProblemCompositeTreeNode.addChild(highFirstRoot, highMarkerNode, [highMarker]);
ProblemCompositeTreeNode.addChild(highFirstRoot, lowMarkerNode, [lowMarker]);
ProblemCompositeTreeNode.addChildren(highFirstRoot, [
{ node: highMarkerNode, markers: [highMarker] },
{ node: lowMarkerNode, markers: [lowMarker] },
]);
expectCorrectOrdering(highFirstRoot);
const lowFirstRoot = getRootNode('lowFirstRoot');
ProblemCompositeTreeNode.addChild(lowFirstRoot, lowMarkerNode, [lowMarker]);
ProblemCompositeTreeNode.addChild(lowFirstRoot, highMarkerNode, [highMarker]);
ProblemCompositeTreeNode.addChildren(lowFirstRoot, [
{ node: lowMarkerNode, markers: [lowMarker] },
{ node: highMarkerNode, markers: [highMarker] },
]);
expectCorrectOrdering(lowFirstRoot);

function expectCorrectOrdering(root: MarkerRootNode): void {
Expand Down Expand Up @@ -124,8 +128,10 @@ describe('problem-composite-tree-node', () => {
const nodeB = createMockMarkerNode(markerB);
const markerInfoNodeA = createMarkerInfo('1', new URI('a'), [nodeA]);
const markerInfoNodeB = createMarkerInfo('2', new URI('b'), [nodeB]);
ProblemCompositeTreeNode.addChild(rootNode, markerInfoNodeA, [markerA]);
ProblemCompositeTreeNode.addChild(rootNode, markerInfoNodeB, [markerB]);
ProblemCompositeTreeNode.addChildren(rootNode, [
{ node: markerInfoNodeA, markers: [markerA] },
{ node: markerInfoNodeB, markers: [markerB] },
]);

expect(rootNode.children.length).to.equal(2);
expect(rootNode.children[0]).to.equal(markerInfoNodeA);
Expand All @@ -138,10 +144,14 @@ describe('problem-composite-tree-node', () => {
const markerA = createMockMarker({ start: { line: 0, character: 10 }, end: { line: 0, character: 10 } }, DiagnosticSeverity.Error);
const nodeA = createMockMarkerNode(markerA);
const markerInfoNodeA = createMarkerInfo('1', new URI('a'), [nodeA]);
ProblemCompositeTreeNode.addChild(rootNode, markerInfoNodeA, [markerA]);
ProblemCompositeTreeNode.addChildren(rootNode, [
{ node: markerInfoNodeA, markers: [markerA] }
]);

markerA.data.severity = DiagnosticSeverity.Hint;
ProblemCompositeTreeNode.addChild(rootNode, markerInfoNodeA, [markerA]);
ProblemCompositeTreeNode.addChildren(rootNode, [
{ node: markerInfoNodeA, markers: [markerA] }
]);

expect(rootNode.children.length).to.equal(1);
expect(rootNode.children[0]).to.equal(markerInfoNodeA);
Expand All @@ -151,15 +161,21 @@ describe('problem-composite-tree-node', () => {
const markerA = createMockMarker({ start: { line: 0, character: 10 }, end: { line: 0, character: 10 } }, DiagnosticSeverity.Error);
const nodeA = createMockMarkerNode(markerA);
const markerInfoNodeA = createMarkerInfo('1', new URI('a'), [nodeA]);
ProblemCompositeTreeNode.addChild(rootNode, markerInfoNodeA, [markerA]);
ProblemCompositeTreeNode.addChildren(rootNode, [
{ node: markerInfoNodeA, markers: [markerA] }
]);

const markerB = createMockMarker({ start: { line: 0, character: 10 }, end: { line: 0, character: 10 } }, DiagnosticSeverity.Error);
const nodeB = createMockMarkerNode(markerB);
const markerInfoNodeB = createMarkerInfo('2', new URI('b'), [nodeB]);
ProblemCompositeTreeNode.addChild(rootNode, markerInfoNodeB, [markerB]);
ProblemCompositeTreeNode.addChildren(rootNode, [
{ node: markerInfoNodeB, markers: [markerB] }
]);

markerA.data.severity = DiagnosticSeverity.Hint;
ProblemCompositeTreeNode.addChild(rootNode, markerInfoNodeA, [markerA]);
ProblemCompositeTreeNode.addChildren(rootNode, [
{ node: markerInfoNodeA, markers: [markerA] }
]);

expect(rootNode.children.length).to.equal(2);
expect(rootNode.children[0]).to.equal(markerInfoNodeB);
Expand All @@ -172,15 +188,21 @@ describe('problem-composite-tree-node', () => {
const markerA = createMockMarker({ start: { line: 0, character: 10 }, end: { line: 0, character: 10 } }, DiagnosticSeverity.Hint);
const nodeA = createMockMarkerNode(markerA);
const markerInfoNodeA = createMarkerInfo('1', new URI('a'), [nodeA]);
ProblemCompositeTreeNode.addChild(rootNode, markerInfoNodeA, [markerA]);
ProblemCompositeTreeNode.addChildren(rootNode, [
{ node: markerInfoNodeA, markers: [markerA] }
]);

const markerB = createMockMarker({ start: { line: 0, character: 10 }, end: { line: 0, character: 10 } }, DiagnosticSeverity.Error);
const nodeB = createMockMarkerNode(markerB);
const markerInfoNodeB = createMarkerInfo('2', new URI('b'), [nodeB]);
ProblemCompositeTreeNode.addChild(rootNode, markerInfoNodeB, [markerB]);
ProblemCompositeTreeNode.addChildren(rootNode, [
{ node: markerInfoNodeB, markers: [markerB] }
]);

markerA.data.severity = DiagnosticSeverity.Error;
ProblemCompositeTreeNode.addChild(rootNode, markerInfoNodeA, [markerA]);
ProblemCompositeTreeNode.addChildren(rootNode, [
{ node: markerInfoNodeA, markers: [markerA] }
]);

expect(rootNode.children.length).to.equal(2);
expect(rootNode.children[0]).to.equal(markerInfoNodeA);
Expand Down
59 changes: 36 additions & 23 deletions packages/markers/src/browser/problem/problem-composite-tree-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,46 @@ export namespace ProblemCompositeTreeNode {
parent.severity = maxSeverity;
};

export function addChild(parent: CompositeTreeNode, child: MarkerInfoNode, markers: Marker<Diagnostic>[]): CompositeTreeNode {
ProblemCompositeTreeNode.setSeverity(child, markers);
export function addChildren(parent: CompositeTreeNode, insertChildren: { node: MarkerInfoNode, markers: Marker<Diagnostic>[] }[]): void {
for (const { node, markers } of insertChildren) {
ProblemCompositeTreeNode.setSeverity(node, markers);
}

const sortedInsertChildren = insertChildren.sort(
(a, b) => (ProblemUtils.severityCompare(a.node.severity, b.node.severity) || compareURI(a.node.uri, b.node.uri))
);

let startIndex = 0;
const children = parent.children as MarkerInfoNode[];
const index = children.findIndex(value => value.id === child.id);
if (index !== -1) {
CompositeTreeNode.removeChild(parent, child);
} if (children.length === 0) {
children.push(child);
CompositeTreeNode.setParent(child, 0, parent);
} else {
let inserted = false;
for (let i = 0; i < children.length; i++) {
// sort by severity, equal severity => sort by URI
if (ProblemUtils.severityCompare(child.severity, children[i].severity) < 0
|| (ProblemUtils.severityCompare(child.severity, children[i].severity) === 0 && compareURI(child.uri, children[i].uri) < 0)) {
children.splice(i, 0, child);
inserted = true;
CompositeTreeNode.setParent(child, i, parent);
break;
};
for (const { node } of sortedInsertChildren) {
const index = children.findIndex(value => value.id === node.id);
if (index !== -1) {
CompositeTreeNode.removeChild(parent, node);
}
if (inserted === false) {
children.push(child);
CompositeTreeNode.setParent(child, children.length - 1, parent);
if (children.length === 0) {
children.push(node);
startIndex = 1;
CompositeTreeNode.setParent(node, 0, parent);
} else {
let inserted = false;
for (let i = startIndex; i < children.length; i++) {
// sort by severity, equal severity => sort by URI
if (ProblemUtils.severityCompare(node.severity, children[i].severity) < 0
|| (ProblemUtils.severityCompare(node.severity, children[i].severity) === 0 && compareURI(node.uri, children[i].uri) < 0)) {
children.splice(i, 0, node);
inserted = true;
startIndex = i + 1;
CompositeTreeNode.setParent(node, i, parent);
break;
};
}
if (inserted === false) {
children.push(node);
startIndex = children.length;
CompositeTreeNode.setParent(node, children.length - 1, parent);
}
}
}
return parent;
}

const compareURI = (uri1: URI, uri2: URI): number =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ProblemManager } from './problem-manager';
import { ProblemUtils } from './problem-utils';
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
import { CancellationToken, Emitter, Event, nls } from '@theia/core';
import debounce = require('@theia/core/shared/lodash.debounce');

@injectable()
export class ProblemDecorationsProvider implements DecorationsProvider {
Expand All @@ -35,11 +36,15 @@ export class ProblemDecorationsProvider implements DecorationsProvider {

@postConstruct()
protected init(): void {
this.problemManager.onDidChangeMarkers(() => {
const newUris = Array.from(this.problemManager.getUris(), stringified => new URI(stringified));
this.onDidChangeEmitter.fire(newUris.concat(this.currentUris));
this.currentUris = newUris;
});
this.problemManager.onDidChangeMarkers(() => this.fireDidDecorationsChanged());
}

protected fireDidDecorationsChanged = debounce(() => this.doFireDidDecorationsChanged(), 50);

protected doFireDidDecorationsChanged(): void {
const newUris = Array.from(this.problemManager.getUris(), stringified => new URI(stringified));
this.onDidChangeEmitter.fire(newUris.concat(this.currentUris));
this.currentUris = newUris;
}

provideDecorations(uri: URI, token: CancellationToken): Decoration | Promise<Decoration | undefined> | undefined {
Expand Down
21 changes: 16 additions & 5 deletions packages/markers/src/browser/problem/problem-tree-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
import { ProblemMarker } from '../../common/problem-marker';
import { ProblemManager } from './problem-manager';
import { ProblemCompositeTreeNode } from './problem-composite-tree-node';
import { MarkerNode, MarkerTree, MarkerOptions, MarkerInfoNode } from '../marker-tree';
import { MarkerNode, MarkerTree, MarkerOptions, MarkerInfoNode, MarkerRootNode } from '../marker-tree';
import { MarkerTreeModel } from '../marker-tree-model';
import { injectable, inject } from '@theia/core/shared/inversify';
import { OpenerOptions, TreeNode } from '@theia/core/lib/browser';
import { Marker } from '../../common/marker';
import { Diagnostic } from '@theia/core/shared/vscode-languageserver-protocol';
import { ProblemUtils } from './problem-utils';
import debounce = require('@theia/core/shared/lodash.debounce');

@injectable()
export class ProblemTree extends MarkerTree<Diagnostic> {
protected markers: { node: MarkerInfoNode, markers: Marker<Diagnostic>[] }[] = [];

constructor(
@inject(ProblemManager) markerManager: ProblemManager,
Expand Down Expand Up @@ -77,12 +79,21 @@ export class ProblemTree extends MarkerTree<Diagnostic> {
}

protected override insertNodeWithMarkers(node: MarkerInfoNode, markers: Marker<Diagnostic>[]): void {
ProblemCompositeTreeNode.addChild(node.parent, node, markers);
const children = this.getMarkerNodes(node, markers);
node.numberOfMarkers = markers.length;
this.setChildren(node, children);
this.markers.push({ node, markers });
this.doInsertNodesWithMarkers();
}

protected doInsertNodesWithMarkers = debounce(() => {
ProblemCompositeTreeNode.addChildren(this.root as MarkerRootNode, this.markers);

for (const { node, markers } of this.markers) {
const children = this.getMarkerNodes(node, markers);
node.numberOfMarkers = markers.length;
this.setChildren(node, children);
}

this.markers.length = 0;
}, 50);
}

@injectable()
Expand Down
101 changes: 0 additions & 101 deletions packages/monaco/src/browser/monaco-diagnostic-collection.ts

This file was deleted.

Loading