Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Optimize marker observation - #7023

Merged
maxbrunsfeld merged 8 commits into
masterfrom
mb-optimize-marker-observation
Jun 4, 2015
Merged

maxbrunsfeld merged 8 commits into
masterfrom
mb-optimize-marker-observation

Conversation

@maxbrunsfeld

Copy link
Copy Markdown
Contributor

Depends on new text-buffer features. See atom/text-buffer#66.

This is one of several optimizations aimed at addressing Atom's slowness when an editor has a lot of markers (e.g. find-and-replace results, spell-check highlights).

Problem

Currently, each decorated marker in the editor is individually observed by the TextEditorPresenter using Marker::onDidChange. Even though the presenter doesn't do much work for markers that are off-screen, just emitting all these change events becomes expensive when there are 10,000+ markers. The main cost is computing each marker's screen coordinates based on the underlying buffer coordinates.

This is a flame graph taken while inserting a newline into a file 2800 line file with 17000 search results. It took 1.5 seconds. The region between the red arrows is emitting marker change events.

screen shot 2015-06-04 at 10 50 45 am

Solution

We've added a new API on TextEditor called ::observeMarkers(), which allows you to observe any marker changes within a particular region of the editor. The presenter now simply recomputes decoration states whenever any markers update. It determines that markers have updated using the text-buffer's ::onDidUpdateMarkers method. This means that most markers are not observed, so they can avoid observing changes to their underlying text-buffer marker, preventing unnecessary screen-coordinate translations.

The same operation as performed above now takes 170 ms. Still not fast, but we've removed a bottleneck.

Conflicts:
	src/text-editor-component.coffee
	src/text-editor-presenter.coffee
@maxbrunsfeld
maxbrunsfeld force-pushed the mb-optimize-marker-observation branch from deef930 to f5895d8 Compare June 4, 2015 00:58
maxbrunsfeld pushed a commit that referenced this pull request Jun 4, 2015
@maxbrunsfeld
maxbrunsfeld merged commit 688cc5e into master Jun 4, 2015
@maxbrunsfeld
maxbrunsfeld deleted the mb-optimize-marker-observation branch June 4, 2015 17:57
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.

1 participant