This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Repository navigation
Optimize buffer search - #72
Merged
Merged
Conversation
17 of 20 tasks
maxbrunsfeld
force-pushed
the
mb-optimize-scan
branch
from
June 8, 2015 23:03
ecf402e to
59e467a
Compare
maxbrunsfeld
force-pushed
the
mb-optimize-scan
branch
from
June 8, 2015 23:57
59e467a to
e33ad78
Compare
Contributor
Author
|
This also improves |
Contributor
Author
|
/cc @nathansobo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
::scanInRange()and::backwardsScanInRange(), since their implementation is a little more complex now.bracket-matcher) work in all cases.Problem
The
scanInRange()method allows the caller to stop the scan by calling thestop()function from within the scan callback. Currently though, we scan the entire buffer range and collect the matches in an Array before calling the callback. This causes scan operations to be slow for large files, even if the caller is only looking for the first match.Here's a flame graph for moving the cursor to the end of the word in a 2.3MB file. There's a bunch of garbage collection pauses due to buffering the matches. The operation took 250ms.
Solution
We call the scan callback as soon as we find each match, so that if
stop()is called, we can avoid any further calls toRegExp.prototype.exec().It's a little tricky for
backwardsScanInRange(). Whereas before we simply scanned the entire range and then reversed the array of matches, we now need to break the range into chunks and scan each chunk. If no matches are found within a chunk, we need to expand the chunk backwards, in case matches straddle chunk boundaries.Here's a flame graph for the same operation as above:
It took 12ms. You can now hold down
alt-rightin a big file without locking the UI.