applyChange emits lots of events when calling replace
#67
Description
More of a question than an issue necessarily.
I noticed when playing around the whitespace's "Convert tabs/spaces to spaces/tabs" functionality that the pane would hang for 3-4 seconds at a time for a decently sized file (say text-buffer.coffee
and its 1400 lines of code). After looking at a flame graph and digging into the code, I realized a lot of this time is spent on @emitter.emit
calls originating from applyChange
being called for each regex replacement (in this case replacing tabs with spaces or vice versa). Specifically, each call to applyChange
emits a will-change
(which happened to have one listener on my machine), and a did-change
listener (which has 4 listeners locally). Disabling the emit events took the run time down to around a third of a second, or about a tenth of the original run time.
Is there a reason why we need to emit so many events in this particular scenario? Would it make sense for calls to replace
or even transact
to only emit the change events once before and once after all the replacements have concluded? If so, how might that look?
I can post some screenshots to clarify the issue if necessary. Thanks!