Skip to content

perf: reorder expensive conditional operand#4592

Merged
WillLillis merged 1 commit intotree-sitter:masterfrom
WillLillis:micro-opts
Jul 12, 2025
Merged

perf: reorder expensive conditional operand#4592
WillLillis merged 1 commit intotree-sitter:masterfrom
WillLillis:micro-opts

Conversation

@WillLillis
Copy link
Member

@WillLillis WillLillis commented Jul 12, 2025

Another tiny performance win I found while trying to learn more about the generate code. In this case, variable_is_used is recursive and can be fairly expensive. By just reordering with the much cheaper grammar_json.word.as_ref().is_none_or(|w| w != name), we get some small wins. This typically hovers around a 1% boost for "simpler" grammars (like tree-sitter-c), while it has no measurable affect on more "complicated" ones (i.e. tree-sitter-systemverilog or tree-sitter-ocaml).

@WillLillis WillLillis merged commit 5ed2c77 into tree-sitter:master Jul 12, 2025
18 checks passed
@WillLillis WillLillis deleted the micro-opts branch July 12, 2025 17:52
@WillLillis WillLillis added ci:backport release-0.25 Backport label perf Performance related labels Jul 12, 2025
@tree-sitter-ci-bot
Copy link

Successfully created backport PR for release-0.25:

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

Labels

ci:backport release-0.25 Backport label perf Performance related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants