From 1a8d7b486d644b0d9ea0914721077a8b9fc0f5a7 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 27 Nov 2015 12:10:48 +0100 Subject: [PATCH] Remove caching by screen rows Because we cannot use them as a cache key, because markers' position can change at any time. Performance-wise this is slow with many markers, as we need to do a lot of buffer-to-screen conversions. --- src/text-editor-presenter.coffee | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 8738357b4..4fd612ec5 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -74,7 +74,7 @@ class TextEditorPresenter getPreMeasurementState: -> @updating = true - @updateBlockDecorations() if @shouldUpdateBlockDecorations + @updateBlockDecorations() @updateVerticalDimensions() @updateScrollbarDimensions() @@ -144,7 +144,6 @@ class TextEditorPresenter @shouldUpdateHiddenInputState = false @shouldUpdateContentState = false @shouldUpdateDecorations = false - @shouldUpdateBlockDecorations = false @shouldUpdateLinesState = false @shouldUpdateTilesState = false @shouldUpdateCursorsState = false @@ -163,7 +162,6 @@ class TextEditorPresenter @shouldUpdateHiddenInputState = true @shouldUpdateContentState = true @shouldUpdateDecorations = true - @shouldUpdateBlockDecorations = true @shouldUpdateLinesState = true @shouldUpdateTilesState = true @shouldUpdateCursorsState = true @@ -194,7 +192,6 @@ class TextEditorPresenter @shouldUpdateLineNumbersState = true @shouldUpdateDecorations = true @shouldUpdateOverlaysState = true - @shouldUpdateBlockDecorations = true @shouldUpdateVerticalScrollState = true @shouldUpdateCustomGutterDecorationState = true @emitDidUpdateState() @@ -1410,32 +1407,27 @@ class TextEditorPresenter setBlockDecorationDimensions: (decoration, width, height) -> screenRow = decoration.getMarker().getHeadScreenPosition().row dimensions = {width, height} - - screenRowDecorations = @blockDecorationsDimensionsByScreenRow[screenRow] ?= {} - screenRowDecorations[decoration.id] = dimensions @blockDecorationsDimensionsById[decoration.id] = dimensions - @setScreenRowHeight( - screenRow, - @lineHeight + @getBlockDecorationsHeight(_.values(screenRowDecorations)) - ) - - @shouldUpdateBlockDecorations = true @shouldUpdateVerticalScrollState = true @emitDidUpdateState() updateBlockDecorations: -> - # TODO: Move this inside `DisplayBuffer` + @heightsByScreenRow = {} blockDecorations = {} + + # TODO: move into DisplayBuffer for decoration in @model.getDecorations(type: "block") blockDecorations[decoration.id] = decoration - for screenRow, decorations of @blockDecorationsDimensionsByScreenRow - for decorationId of decorations when not blockDecorations.hasOwnProperty(decorationId) + for decorationId of @blockDecorationsDimensionsById + unless blockDecorations.hasOwnProperty(decorationId) delete @blockDecorationsDimensionsById[decorationId] - delete @blockDecorationsDimensionsByScreenRow[screenRow][decorationId] - @shouldUpdateVerticalScrollState = true + for decorationId, decoration of blockDecorations + screenRow = decoration.getMarker().getHeadScreenPosition().row + @heightsByScreenRow[screenRow] ?= @lineHeight + @heightsByScreenRow[screenRow] += @blockDecorationsDimensionsById[decorationId].height observeCursor: (cursor) -> didChangePositionDisposable = cursor.onDidChangePosition =>