You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit db84045
Browse filesBrowse the repository at this point in the historyBrowse files
parser: the marker table indexed, and the phase profile that says where a parse really goes
Item 2 of `docs/parser-review.md` §5.3 said the template path was where a 2× lived. **It is not**, and the value of this
commit is half an optimization and half the instrument that disproved the premise.
## What was changed
`Marker::complete` asked a `HashMap<usize, bool>` three questions per node, `close_mark` scanned the open stack, and a
rollback removed one map entry per position closed since. The positions are event indices on a dense, append-only
stream, so the table is now a `Vec<u8>` in lockstep with the events — one byte per event, three states — and:
```text
close_mark 4 hash lookups + 2 linear scans per node → three loads, and the LIFO pop is the common case
rollback remove an entry per position closed since → truncate the table
```
Measured on 3.98 MB of libstdc++ headers, three runs each side: **2.48–2.52 → 2.54–2.57 MB/s**. Real, reproducible,
and 2.5 % — not 2×. It is kept because it is strictly less work per node and a rollback is now a truncation.
## The instrument, and what it says
`CPPLS_PARSER_STATS=1` now prints a phase table (inclusive times, `parser/phases.rs`) and a set of counts. On the
3.98 MB unit — 972 104 tokens, 688 159 nodes, 2 467 911 events, 1.59 s:
```text
declaration 769 ms 27 306 calls 28.2 µs each
specifiers 192 ms 64 052 calls 3.0 µs each ← the largest single named item, 12 % of the parse
declarator 82 ms 43 524 calls 1.9 µs each
expression 69 ms 49 399 calls 1.4 µs each
template-arguments 32 ms 19 114 calls 1.7 µs each
tree building 187 ms 688 159 nodes 12 %
lexing 27 ms 978 289 tokens 2 %
doc layer 10.6 ms 8 887 comment groups 0.7 %
counts: 115 086 checkpoints (0.12/token), 15 665 rollbacks, 38 411 type-name questions, 2 751 `>` questions
```
**Per-file cost is flat**: the slowest ten files of the corpus are 113–128 µs/KB against an average of 110. There is no
pathological construct in libstdc++, so the 2.5× this corpus costs over plain code is not one hot spot — it is the
ordinary price of the constructs headers are made of. That is why the "template path" hypothesis was wrong, and it is
now written down with the numbers instead of the guess.
The instrument is process-wide behind a mutex rather than thread-local, because `tests/no_global_state.rs` rejected a
thread-local — correctly, and it is the second time that test has caught this shape. When the probe is off (the
default) the cost is one `OnceLock` load per instrumented call and nothing else: measured 2.57 MB/s off against
2.50 MB/s with the table on.
## Where the next 10 % are
`parse_decl_specifier_seq` is 12 % of the parse at 3.0 µs a call over 64 052 calls, and the declaration machinery
around it is another ~25 %. Those are named in `docs/parser-review.md` §5.3 as the next targets; **a 2× is not
available from any one of them**, which is the finding this commit contributes.
`cargo test --workspace`: 79 suites ok; the one failure is the `diagnostics_stable` that was red before this work.
0 commit comments