Add selection above/below gets really slow


Hi, I’ve noticed that Atom’s commands editor:add-selection-above and editor:add-selection-below become really slow by the time you add 50+ lines to the selection. It gets progressively worse the more lines you add to the selection using those commands.

I can’t find any existing bug recorded for it, so I thought I’d try to help fix it. (I’ve never made changes to Atom before, so this might make a good first opportunity :slight_smile:).

So far, I used the Dev Tools to profile the problem, and I think I’ve found the function that is taking up the majority of the time: MarkerLayer.createMarker. Its time is spread mostly between calls to TextEditor.addSelection and TextEditor.addCursor, via its call to Emitters.emit on 'did-create-marker'. It also may be resulting in calls to itself, again via Emitters.

I see that MarkerLayer.createMarker checks a field emitCreateMarkerEvents that can be used to skip emitting events. Could the solution be to not emit events for some subset of the calls to MarkerLayer.createMarker?

I’m not really sure where to go from here, so any pointers or things to try would be useful. I can also share the .cpuprofile I collected with you, but Discuss didn’t let me attach it to this post.



There is this Issue for history:

Speeding up multiple selections and batching together events is something that the core team has been working on quite a bit. The MarkerLayer system is actually a relatively recent addition to the Atom API to help with performance issues. You may want to look at the recent PRs by @nathansobo and @as-cii to get some context on the directions they’re going with performance improvements.


Ah, so there is an issue already logged about this. I tried searching, but couldn’t find it.

It looks like a much more complex thing than I originally thought, and @nathansobo and @as-cii seem to have an actual plan to resolve these issues.