Skip to content

language: Improve highlight map resolution#52183

Merged
MrSubidubi merged 9 commits intomainfrom
highlight-map-better-resolution
Mar 25, 2026
Merged

language: Improve highlight map resolution#52183
MrSubidubi merged 9 commits intomainfrom
highlight-map-better-resolution

Conversation

@MrSubidubi
Copy link
Copy Markdown
Member

@MrSubidubi MrSubidubi commented Mar 23, 2026

This PR refactors the highlight map capture name resolution to be faster and more predictable. Speficically,

  • it changes the capture name matching to explicit prefix matching (e.g., function.call.whatever.jsx will now be matched by only function, function.call, function.call.whatever and function.call.whatever.jsx). This matches the behavior VSCode has
  • resolving highlights is now much more efficient, as we now look up captures in a BTreeMap as opposed to searching in a Vector for these.

This substantially improves the performance for resolving capture names against themes. With the benchmark added here for creating the HighlightMap, we see quite some improvements:

Running benches/highlight_map.rs (target/release/deps/highlight_map-f99da68650aac85b)
HighlightMap::new/small_captures/small_theme
                        time:   [161.90 ns 162.70 ns 163.55 ns]
                        change: [-39.027% -38.352% -37.742%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild
HighlightMap::new/small_captures/large_theme
                        time:   [231.37 ns 233.02 ns 234.70 ns]
                        change: [-91.570% -91.516% -91.464%] (p = 0.00 < 0.05)
                        Performance has improved.
HighlightMap::new/large_captures/small_theme
                        time:   [991.82 ns 994.94 ns 998.50 ns]
                        change: [-50.670% -50.443% -50.220%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
  5 (5.00%) high mild
HighlightMap::new/large_captures/large_theme
                        time:   [1.6528 µs 1.6650 µs 1.6784 µs]
                        change: [-91.684% -91.637% -91.593%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) low mild

For large themes and many capture names, the revised approach is much faster.

With that in place, we can also add better fallbacks whenever we change tokens, since e.g. a change from @variable to @preproc would previously cause tokens to not be highlighted at all, whereas now we can add fallbacks for such cases more efficiently. I'll add this later on to this PR.

Self-Review Checklist

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Improved resolution speed of theme highlight capture names. This might change highlighting in some rare edge cases, but should overall make highlighting more predicatable. Theme captures will now follow a strict prefix matching, so e.g. function.call.decorator.jsxwill now be matched by onlyfunction, function.call, function.call.decoratorandfunction.call.decorator.jsx` with the most specific capture always taking precedence.

osiewicz and others added 8 commits March 23, 2026 09:50
Co-authored-by: MrSubidubi <dev@bahn.sh>
Co-authored-by: Gaauwe Rombouts <mail@grombouts.nl>
Co-authored-by: MrSubidubi <dev@bahn.sh>
Co-authored-by: Gaauwe Rombouts <mail@grombouts.nl>
Co-authored-by: Gaauwe Rombouts <mail@grombouts.nl>
Co-authored-by: MrSubidubi <dev@bahn.sh>
Co-authored-by: Gaauwe Rombouts <mail@grombouts.nl>
Co-authored-by: MrSubidubi <dev@bahn.sh>
Co-authored-by: Gaauwe Rombouts <mail@grombouts.nl>
Co-authored-by: MrSubidubi <dev@bahn.sh>
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 23, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Mar 23, 2026
@github-actions
Copy link
Copy Markdown

📏 PR Size: 520 lines changed (Size L)

Please note: this PR exceeds the 400 LOC soft limit.

  • Consider splitting into separate PRs if the changes are separable
  • Ensure the PR description includes a guided tour in the "How to Review" section so reviewers know where to start

@MrSubidubi MrSubidubi marked this pull request as ready for review March 25, 2026 09:00
@zed-codeowner-coordinator zed-codeowner-coordinator bot requested review from a team, Anthony-Eid, osiewicz and smitbarmase and removed request for a team March 25, 2026 09:00
@MrSubidubi MrSubidubi merged commit e63bd1a into main Mar 25, 2026
34 checks passed
@MrSubidubi MrSubidubi deleted the highlight-map-better-resolution branch March 25, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement large-pr staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants