From b795358075782f66df74eed911250565e1fa3c6a Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Wed, 1 Feb 2017 06:59:18 -0800 Subject: [PATCH] Some perf tweaks --- scripts/code.sh | 3 ++ .../editor/common/model/editableTextModel.ts | 14 +++++---- src/vs/editor/common/model/modelLine.ts | 4 +-- .../common/model/textModelWithDecorations.ts | 5 ++- .../common/model/textModelWithMarkers.ts | 8 ----- .../common/viewModel/prefixSumComputer.ts | 31 ++++++++++--------- 6 files changed, 33 insertions(+), 32 deletions(-) diff --git a/scripts/code.sh b/scripts/code.sh index fe3d014c633..4ce722d2b27 100755 --- a/scripts/code.sh +++ b/scripts/code.sh @@ -41,4 +41,7 @@ function code() { exec "$CODE" . "$@" } +# Use the following to get v8 tracing: +# code --js-flags="--trace-hydrogen --trace-phase=Z --trace-deopt --code-comments --hydrogen-track-positions --redirect-code-traces" "$@" + code "$@" diff --git a/src/vs/editor/common/model/editableTextModel.ts b/src/vs/editor/common/model/editableTextModel.ts index 41afc3d1b1c..a76c6d6eeae 100644 --- a/src/vs/editor/common/model/editableTextModel.ts +++ b/src/vs/editor/common/model/editableTextModel.ts @@ -713,12 +713,14 @@ export class EditableTextModel extends TextModelWithDecorations implements edito } let markers = line.getMarkers(); - for (let j = 0, lenJ = markers.length; j < lenJ; j++) { - foundMarkersCnt++; - let markerId = markers[j].id; - let marker = this._markerIdToMarker[markerId]; - if (marker.position.lineNumber !== line.lineNumber) { - throw new Error('Misplaced marker with id ' + markerId); + if (markers !== null) { + for (let j = 0, lenJ = markers.length; j < lenJ; j++) { + foundMarkersCnt++; + let markerId = markers[j].id; + let marker = this._markerIdToMarker[markerId]; + if (marker.position.lineNumber !== line.lineNumber) { + throw new Error('Misplaced marker with id ' + markerId); + } } } } diff --git a/src/vs/editor/common/model/modelLine.ts b/src/vs/editor/common/model/modelLine.ts index 7c7340aef50..a001a35c9d3 100644 --- a/src/vs/editor/common/model/modelLine.ts +++ b/src/vs/editor/common/model/modelLine.ts @@ -721,9 +721,9 @@ export class ModelLine { public getMarkers(): LineMarker[] { if (!this._markers) { - return []; + return null; } - return this._markers.slice(0); + return this._markers; } public updateLineNumber(markersTracker: MarkersTracker, newLineNumber: number): void { diff --git a/src/vs/editor/common/model/textModelWithDecorations.ts b/src/vs/editor/common/model/textModelWithDecorations.ts index 772f25d7d28..927068c5065 100644 --- a/src/vs/editor/common/model/textModelWithDecorations.ts +++ b/src/vs/editor/common/model/textModelWithDecorations.ts @@ -347,7 +347,10 @@ export class TextModelWithDecorations extends TextModelWithMarkers implements ed } for (let lineNumber = filterStartLineNumber; lineNumber <= filterEndLineNumber; lineNumber++) { - let lineMarkers = this._getLineMarkers(lineNumber); + let lineMarkers = this._lines[lineNumber - 1].getMarkers(); + if (lineMarkers === null) { + continue; + } for (let i = 0, len = lineMarkers.length; i < len; i++) { let lineMarker = lineMarkers[i]; let internalDecorationId = lineMarker.internalDecorationId; diff --git a/src/vs/editor/common/model/textModelWithMarkers.ts b/src/vs/editor/common/model/textModelWithMarkers.ts index 405af8019ee..939e3fa2eae 100644 --- a/src/vs/editor/common/model/textModelWithMarkers.ts +++ b/src/vs/editor/common/model/textModelWithMarkers.ts @@ -137,14 +137,6 @@ export class TextModelWithMarkers extends TextModelWithTokens implements ITextMo return Object.keys(this._markerIdToMarker).length; } - protected _getLineMarkers(lineNumber: number): LineMarker[] { - if (lineNumber < 1 || lineNumber > this.getLineCount()) { - throw new Error('Illegal value ' + lineNumber + ' for `lineNumber`'); - } - - return this._lines[lineNumber - 1].getMarkers(); - } - _removeMarker(id: string): void { let marker = this._markerIdToMarker[id]; if (!marker) { diff --git a/src/vs/editor/common/viewModel/prefixSumComputer.ts b/src/vs/editor/common/viewModel/prefixSumComputer.ts index 819d5fdbf5f..7fbb6afe942 100644 --- a/src/vs/editor/common/viewModel/prefixSumComputer.ts +++ b/src/vs/editor/common/viewModel/prefixSumComputer.ts @@ -33,12 +33,13 @@ export class PrefixSumComputer { /** * prefixSum[i], 0 <= i <= prefixSumValidIndex can be trusted */ - private prefixSumValidIndex: number; + private prefixSumValidIndex: Int32Array; constructor(values: Uint32Array) { this.values = values; this.prefixSum = new Uint32Array(values.length); - this.prefixSumValidIndex = -1; + this.prefixSumValidIndex = new Int32Array(1); + this.prefixSumValidIndex[0] = -1; } public getCount(): number { @@ -60,13 +61,13 @@ export class PrefixSumComputer { this.values.set(oldValues.subarray(insertIndex), insertIndex + insertValuesLen); this.values.set(insertValues, insertIndex); - if (insertIndex - 1 < this.prefixSumValidIndex) { - this.prefixSumValidIndex = insertIndex - 1; + if (insertIndex - 1 < this.prefixSumValidIndex[0]) { + this.prefixSumValidIndex[0] = insertIndex - 1; } this.prefixSum = new Uint32Array(this.values.length); - if (this.prefixSumValidIndex >= 0) { - this.prefixSum.set(oldPrefixSum.subarray(0, this.prefixSumValidIndex + 1)); + if (this.prefixSumValidIndex[0] >= 0) { + this.prefixSum.set(oldPrefixSum.subarray(0, this.prefixSumValidIndex[0] + 1)); } } @@ -78,8 +79,8 @@ export class PrefixSumComputer { return; } this.values[index] = value; - if (index - 1 < this.prefixSumValidIndex) { - this.prefixSumValidIndex = index - 1; + if (index - 1 < this.prefixSumValidIndex[0]) { + this.prefixSumValidIndex[0] = index - 1; } } @@ -108,11 +109,11 @@ export class PrefixSumComputer { this.values.set(oldValues.subarray(startIndex + cnt), startIndex); this.prefixSum = new Uint32Array(this.values.length); - if (startIndex - 1 < this.prefixSumValidIndex) { - this.prefixSumValidIndex = startIndex - 1; + if (startIndex - 1 < this.prefixSumValidIndex[0]) { + this.prefixSumValidIndex[0] = startIndex - 1; } - if (this.prefixSumValidIndex >= 0) { - this.prefixSum.set(oldPrefixSum.subarray(0, this.prefixSumValidIndex + 1)); + if (this.prefixSumValidIndex[0] >= 0) { + this.prefixSum.set(oldPrefixSum.subarray(0, this.prefixSumValidIndex[0] + 1)); } } @@ -130,11 +131,11 @@ export class PrefixSumComputer { index = toUint32(index); - if (index <= this.prefixSumValidIndex) { + if (index <= this.prefixSumValidIndex[0]) { return this.prefixSum[index]; } - let startIndex = this.prefixSumValidIndex + 1; + let startIndex = this.prefixSumValidIndex[0] + 1; if (startIndex === 0) { this.prefixSum[0] = this.values[0]; startIndex++; @@ -147,7 +148,7 @@ export class PrefixSumComputer { for (let i = startIndex; i <= index; i++) { this.prefixSum[i] = this.prefixSum[i - 1] + this.values[i]; } - this.prefixSumValidIndex = Math.max(this.prefixSumValidIndex, index); + this.prefixSumValidIndex[0] = Math.max(this.prefixSumValidIndex[0], index); return this.prefixSum[index]; }