mirror of
https://github.com/tree-sitter/tree-sitter.git
synced 2026-09-10 07:26:23 -04:00
Replace the owned `Rule`-tree grammar with a flat, pooled representation. `Rule` nodes live in a `RulePool` arena and reference their children and params by index (`RuleId`). Strings are interned in a `StrPool` and referred to by `StrId`. Productions are stored as flat `ProductionStep`/`Production` slices indexed per variable, rather than as nested vectors hanging off each `SyntaxVariable`. This drops the per-rule heap allocation of the owned-tree form and is the groundwork for the later table-building optimizations. `parse_grammar` builds the pool, the prepare passes rewrite nodes in place, and `prepare_grammar` returns a `PreparedGrammar` bundle that owns the run's `StrPool` alongside the grammars. `build_tables`, `node_types`, and `render` borrow that pool and resolve `StrId`s only at the output boundary. Shows an average ~10% walltime reduction when combined with the previous commit, with nearly all of the savings in `build_tables`. The `prepare` stage is also ~70% faster and much more stable, but this contributes much less to overall generate time. Improving early stages such as `prepare` will be important for future interactive uses. |
||
|---|---|---|
| .. | ||
| error_corpus | ||
| grammars | ||
| template_corpus | ||
| test_grammars | ||
| fixtures.json | ||