Skip to content

Commit

Permalink
[foldgutter and annotatescrollbar addon] Schedule update on changes i…
Browse files Browse the repository at this point in the history
…nstead of change

The setTimeout/clearTimeout overhead of re-scheduling on every change in a large operation can be significant. This cuts the time of a particularly large operation I was testing from 5s to 2.5s (replacing some text in ~5000 lines). The majority of the rest of the time coming from rescheduling of the highlight worker inside the startWorker call.
  • Loading branch information
alur authored and marijnh committed Sep 6, 2019
1 parent 538c4dc commit ab766ce
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions addon/fold/foldgutter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
cm.clearGutter(cm.state.foldGutter.options.gutter);
cm.state.foldGutter = null;
cm.off("gutterClick", onGutterClick);
cm.off("change", onChange);
cm.off("changes", onChange);
cm.off("viewportChange", onViewportChange);
cm.off("fold", onFold);
cm.off("unfold", onFold);
Expand All @@ -26,7 +26,7 @@
cm.state.foldGutter = new State(parseOptions(val));
updateInViewport(cm);
cm.on("gutterClick", onGutterClick);
cm.on("change", onChange);
cm.on("changes", onChange);
cm.on("viewportChange", onViewportChange);
cm.on("fold", onFold);
cm.on("unfold", onFold);
Expand Down
4 changes: 2 additions & 2 deletions addon/scroll/annotatescrollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
cm.on("markerAdded", this.resizeHandler);
cm.on("markerCleared", this.resizeHandler);
if (options.listenForChanges !== false)
cm.on("change", this.changeHandler = function() {
cm.on("changes", this.changeHandler = function() {
scheduleRedraw(250);
});
}
Expand Down Expand Up @@ -116,7 +116,7 @@
this.cm.off("refresh", this.resizeHandler);
this.cm.off("markerAdded", this.resizeHandler);
this.cm.off("markerCleared", this.resizeHandler);
if (this.changeHandler) this.cm.off("change", this.changeHandler);
if (this.changeHandler) this.cm.off("changes", this.changeHandler);
this.div.parentNode.removeChild(this.div);
};
});

0 comments on commit ab766ce

Please sign in to comment.