perf: More efficient computation of used symbols#4568
Merged
WillLillis merged 1 commit intotree-sitter:masterfrom Jul 10, 2025
Merged
perf: More efficient computation of used symbols#4568WillLillis merged 1 commit intotree-sitter:masterfrom
WillLillis merged 1 commit intotree-sitter:masterfrom
Conversation
As the call to `symbol_is_used` does not depend on the production, it is more efficient to call it only once outside the loop over productions. I'm not sure if `rustc` is able to do this optimization on its own (it would need to know that the function is pure, which sounds difficult in general).
WillLillis
approved these changes
Jul 8, 2025
|
Successfully created backport PR for |
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.
As the call to
symbol_is_useddoes not depend on the production, it is more efficient to call it only once outside the loop over productions.More broadly, the reachable symbols are currently computed at three stages of parser generation (listed here from upstream to downstream):
parse_grammar.rs, where I added the warning in feat: Warn about unreachable variables #4567)flatten_grammar.rs)build_tables.rs)I'm not clear on whether all those stages are useful - can the reachability of some symbols change because of some intermediate transformations?