This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
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.
Problem
While @leroix and I were looking into the performance of the new
findWordsWithSubsequence
method and its use in autocomplete-plus, we noticed that a huge amount of time was being spent in theCursor.getCurrentWordBufferRange
method.There are a few reasons why this method is slow:
TextBuffer.scanInRange
API rather than a native search API from superstring.scanInRange
APIs are especially inefficient when they are passed RegExps that can potentially match across line breaks. Currently, RegExps that contain negated character classes (e.g.[^x]
are assumed to be potentially multi-line.getCurrentWordBufferRange
uses a negated character class based on theeditor.nonWordCharacters
config setting.Solution
We should optimize
scanInRange
, ideally using superstring's native search functionality.First step
This PR expands the set of search APIs. The final list of search APIs will be as follows:
find
findSync
findAll
findAllSync
findInRange
findInRangeSync
findAllInRange
findAllInRangeSync
Before actually changing
TextBuffer.scanInRange
, I'm going to update Atom to use the native API just forCursor.getCurrentWordBufferRange
. That will fix the most immediate performance problem. Then later we can take on the more risky task of updatingscanInRange
./cc @nathansobo