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.
This operation took 300ms.
Here's a flame graph that I recorded of the same operation with this fix:
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.
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
.This operation took 300ms.
Here's a flame graph that I recorded of the same operation with this fix:
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