Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Find brackets to highlight using the Tree-sitter syntax tree#367

Merged
maxbrunsfeld merged 5 commits intomasterfrom
mb-use-syntax-tree
Nov 20, 2018
Merged

Find brackets to highlight using the Tree-sitter syntax tree#367
maxbrunsfeld merged 5 commits intomasterfrom
mb-use-syntax-tree

Conversation

@maxbrunsfeld
Copy link
Contributor

@maxbrunsfeld maxbrunsfeld commented Nov 16, 2018

Description of the Change

Currently, this package finds matching brackets by performing a regex search and keeping track of the nesting level of bracket characters. The code for finding matching HTML tags is even more complicated.

In this PR, I've updated the package to find matching tokens using syntax trees provided by Tree-sitter, when they are available.

Benefits

The performance of bracket matching is vastly improved. Here's a flame graph that I recorded in the current version of Atom when moving the cursor across this opening parenthesis in Atom's text-editor-component-spec.js.

screen shot 2018-11-16 at 2 46 03 pm

This operation took 300ms.

Here's a flame graph that I recorded of the same operation with this fix:

screen shot 2018-11-16 at 3 08 30 pm

The operation now takes 0.75ms; the syntax tree makes the operation basically free.

Possible Drawbacks

This improvement only takes effect for languages with Tree-sitter parsers.

Applicable Issues

Fixes #348
Fixes #355

}
})
if (startRange && endRange) return {startRange, endRange}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one method takes the place of the the TagFinder class.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tag matching doesn't work in HTML with tree-sitter enabled [performance]: Low frame rate when the matching bracket spans several hundreds of lines

1 participant