perf(core): value STEP reals in the grammar walk instead of re-parsing them
Self-driven work from the native instruction-count hillclimb (campaign 2), so no issue; labelled unqueued.
What was unnecessary
Every STEP number was walked twice. First scan_step_numeric_literal checked the grammar and found the literal's end (#5266/#7779), at about 148 instructions per call. Then fast_float2::parse_partial walked the same, already-validated bytes again to value them, at about 223 instructions per call. On advanced_model, read_step_number runs 5.37M times and costs 2.24G Ir, 13% of geometry.
Change
scan::<VALUE> is the one grammar walk, unchanged; the other callers keep VALUE = false, so their scan costs the same. For read_step_number, the same walk also:
- folds the digits into a
u64mantissa (read only when there are at most 19 digits); - reads the exponent, saturated far outside the exact range.
When mantissa <= 2^53 and |exponent - fraction digits| <= 22, the value is m * 10^k or m / 10^k. Both operands are exact f64s, so the single IEEE operation is the correctly rounded value of the decimal, which is exactly what fast_float2 returns (Clinger's fast path). The sign is applied afterwards, so -0. keeps its sign bit. This subsumes #7880's N. path, which was the same computation with k = 0.
Everything else still goes to fast_float2::parse_partial. That covers more than 19 digits, mantissas above 2^53, |power| > 22, and 1.E400 (which stays Unrepresentable). Integers of up to 18 digits take the walk's mantissa, since they cannot leave i64; longer ones keep the checked walk, so i64::MIN and overflow behave as before.
parse_step_numeric (generic over f32/f64) is untouched. Valuing in f64 and then narrowing to f32 would round twice. No unsafe code, no new state.
About 99.5% of the REAL literals in advanced_model, schependomlaan and ISSUE_129 take the exact path (counted from the files).
Performance verdict
Cold, single-thread Callgrind via scripts/perf/instructions.sh (the --cold probe), base main 004934fa88 (no rust/ change from there to this branch's base 63aeb6a82f), Valgrind 3.26.0, Pop x86_64. These are instruction counts only: no wall-time or browser-speed claim is made.
Tuning fixtures: FZK, advanced_model, schependomlaan, ISSUE_129. Holter is the holdout, checked only here at acceptance.
| Fixture | Phase | Before Ir | After Ir | Δ |
|---|---|---|---|---|
| FZK | Parse | 90,464,330 | 90,366,302 | -0.11% |
| FZK | Scan/prepass | 55,377,490 | 55,363,948 | -0.02% |
| FZK | Lookup | 11,766,550 | 11,739,514 | -0.23% |
| FZK | Preprocess | 23,232,378 | 23,175,126 | -0.25% |
| FZK | Geometry | 342,404,967 | 341,749,436 | -0.19% |
| FZK | Pipeline | 432,874,522 | 432,120,963 | -0.17% |
| advanced_model | Parse | 979,435,806 | 979,211,604 | -0.02% |
| advanced_model | Scan/prepass | 973,349,199 | 973,162,117 | -0.02% |
| advanced_model | Lookup | 229,983 | 229,983 | +0.00% |
| advanced_model | Preprocess | 5,716,130 | 5,679,195 | -0.65% |
| advanced_model | Geometry | 17,165,943,981 | 16,189,945,318 | -5.69% |
| advanced_model | Pipeline | 18,145,404,666 | 17,169,181,810 | -5.38% |
| schependomlaan | Parse | 1,418,372,532 | 1,417,876,392 | -0.03% |
| schependomlaan | Scan/prepass | 951,772,820 | 951,733,359 | -0.00% |
| schependomlaan | Lookup | 454,306,360 | 453,889,186 | -0.09% |
| schependomlaan | Preprocess | 8,760,859 | 9,035,462 | +3.13% |
| schependomlaan | Geometry | 2,294,618,638 | 2,264,103,015 | -1.33% |
| schependomlaan | Pipeline | 3,713,013,248 | 3,682,001,491 | -0.84% |
| ISSUE_129 | Parse | 257,065,408 | 256,924,393 | -0.05% |
| ISSUE_129 | Scan/prepass | 251,436,897 | 251,313,340 | -0.05% |
| ISSUE_129 | Lookup | 21,453 | 21,453 | +0.00% |
| ISSUE_129 | Preprocess | 5,476,728 | 5,459,434 | -0.32% |
| ISSUE_129 | Geometry | 25,630,362,629 | 25,589,614,804 | -0.16% |
| ISSUE_129 | Pipeline | 25,887,460,470 | 25,846,571,732 | -0.16% |
| Holter (holdout) | Parse | 4,897,361,125 | 4,897,484,652 | +0.00% |
| Holter (holdout) | Scan/prepass | 4,207,203,960 | 4,207,384,011 | +0.00% |
| Holter (holdout) | Lookup | 677,871,380 | 677,840,784 | -0.00% |
| Holter (holdout) | Preprocess | 5,197,694 | 5,173,044 | -0.47% |
| Holter (holdout) | Geometry | 25,000,452,946 | 24,578,312,028 | -1.69% |
| Holter (holdout) | Pipeline | 29,897,921,942 | 29,475,904,725 | -1.41% |
| Fixture | Meshes / vertices / triangles | Fingerprint base | Fingerprint branch |
|---|---|---|---|
| FZK | 285 / 35,940 / 20,322 (unchanged) | 7377db33331a3523 | 7377db33331a3523 |
| advanced_model | 11,471 / 2,795,258 / 1,360,732 (unchanged) | c6585cf25dbb3907 | c6585cf25dbb3907 |
| schependomlaan | 6,057 / 424,334 / 260,964 (unchanged) | c41dfe123a8cda83 | c41dfe123a8cda83 |
| ISSUE_129 | 1,402 / 218,929 / 136,241 (unchanged) | 954ce9d1850bbde1 | 954ce9d1850bbde1 |
| Holter | 109,514 / 4,515,161 / 2,895,362 (unchanged) | 500e89efcdd091fa | 500e89efcdd091fa |
schependomlaan's preprocess phase rises by about 0.3M instructions, roughly 0.008% of pipeline. #9632 and #9635, which share no code with this PR or with each other, show the same rise on the same phase, so it comes from the measurement run, not from this change.
The fingerprints are perf_probe --fingerprint, i.e. ordered mesh payloads: positions, normals, indices, colours, origins, bounds and transforms. They exclude text, materials, UVs, textures and instancing. A changed float anywhere in geometry input would move them.
Combined with the sibling hillclimb levers
These are separate branches off main. The three accepted levers stacked (#9632 + #9636 + #9635, cherry-picked onto main, 193e1818e0), cold single-thread Callgrind pipeline instructions against the main baseline:
| Fixture | Stacked | Sum of the three measured alone |
|---|---|---|
| FZK | -1.68% | -1.70% |
| advanced_model | -18.46% | -18.54% |
| schependomlaan | -3.99% | -3.90% |
| ISSUE_129 | -0.63% | -0.94% |
| Holter (holdout) | -9.15% | -9.13% |
Fingerprints are identical on all five fixtures when stacked. The code changes touch disjoint files, and the ledger entries are anchored at different bullets, so a sequential trial merge onto main is clean.
ISSUE_129 recovers 0.31 points less stacked than alone. Pair builds isolate this: #9635 with #9632 gives +51M Ir, #9635 with #9636 gives +30M. The per-function diff puts most of it in unexported glibc malloc internals. #9635 swaps outsized tables for fresh ones and the other two remove allocations, so the heap ends up in a different state, and that changes the allocator's internal path costs. It is not a logic interaction, and the output is identical. #9643 (stacked on #9632, measured alone against main) adds advanced_model -14.1% and Holter -2.4% on top; its combined figure will be added once it lands.
All four accepted levers stacked (#9632 + #9636 + #9635 + #9643, cherry-picked onto main, cfd66cd1d5): FZK -1.67%, advanced_model -28.27%, schependomlaan -4.76%, ISSUE_129 -0.77%, Holter -10.79% pipeline instructions, with fingerprints identical on all five fixtures. advanced_model falls short of the sum of its parts (-32.7%) by design: #9636 makes each point read cheaper, and #9643 removes most of those reads.
Identity and tests
Revert oracle ("Changed tests observe production"). The first head was UNOBSERVED, because bit-identity tests pass on main too. Fixed in b3f7d747ae: numeric_literal_tests.rs now defines two thread-local probes, which read_step_number bumps under cfg(test) only. a_typical_coordinate_is_valued_in_one_walk_without_fast_float asserts that exact-range reals are valued in the walk with zero fast_float2 calls, and that out-of-range ones still fall back. The local --ci oracle on Pop gives OBSERVED: 11/11 pass on the branch, and with production reverted 10 pass and 1 fails.
- New
single_pass_reader_matches_fast_float_and_i64_bit_for_bit: 200k generated literals plus hand-picked edges, all compared againstfast_float2bit for bit and againststr::parse::<i64>. The generated literals cover signs, leading zeros, bare dots, up to 20 integer and 20 fraction digits, and exponents. The edges include 2^53 ± 1, 1E22/1E23, 1.E-22/1.E-23,-0.,-0.E-400, i64::MIN/MAX and overflow, and saturated exponents. - The existing shared-vector tests (#5266, the TypeScript grammar twin) pass. All 10
numeric_literaltests pass. - Qualification on Pop, commit
f7d10877b5(all pass):cargo clippy -p ifc-lite-core -p ifc-lite-geometry -p ifc-lite-processing --all-targets -- -D warnings: clean.cargo test -p ifc-lite-core: 575 passed, 0 failed, including the 200k-literal bit-for-bit test and the shared-vector grammar tests.cargo test -p ifc-lite-geometry: 3,154 passed, 0 failed. This ran with the 121-model corpus linked in, sowatertightness_census_and_triangulator_invarianceactually measured. The two heavy-fixture tests stayed#[ignore]d as usual.cargo test -p ifc-lite-processing: 1,338 passed, 0 failed, includingmesh_output_matches_pinned_manifest.cargo test -p ifc-lite-export --test export_golden: 18 passed.cargo check --target wasm32-unknown-unknown -p ifc-lite-wasm: compiles.- The checkout was clean before and after.
- The current head adds only the ledger move (
git diff f7d10877b5 HEADtouches onlyscripts/perf/README.md). - The wasm32 mesh-determinism manifest is not run locally;
determinism.ymlcovers it, and the arithmetic is IEEE-exact on both targets.
This is independent of #9632 and #9635 (no shared code), and is a separate branch off main. Ledger entry added under "Shipped wins". ci:native-adapter is requested because this changes geometry input reading.
🤖 Generated with Claude Code