Improve document preprocessing#1530
Open
thecrypticace wants to merge 2 commits intofeat/document-no-async-findfrom
Open
Improve document preprocessing#1530thecrypticace wants to merge 2 commits intofeat/document-no-async-findfrom
thecrypticace wants to merge 2 commits intofeat/document-no-async-findfrom
Conversation
This is both faster and uses less memory — especially on large documents
c1b2c98 to
fef9459
Compare
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In the language server we do a lot of scanning of documents for:
Additionally, the user can provide custom regexes to target arbitrary text as class lists.
We don't want to detect any of these inside comments so we preprocess documents by replacing comments with spaces. Additionally, in JS, we replace regex literals with spaces as we don't want something like
/<style>/to accidentally get detected the start of an embedded language.This process takes a small emount of time and memory and can be complicated to do correctly. Here I've replaced the existing scanner/parser with a UTF-16 code unit based version (e.g.
String#charCodeAt) that is more correct than regexes (JS has no support for recursive patterns), uses less memory, and is up to ~8x faster in my benchmarks.The implementation here isn't perfect either but it is a bit better.