perf(geometry): quantise weld and orient keys without a libm round call
Self-driven work from the native instruction-count hillclimb (campaign 2, round 6), so no issue; labelled unqueued. Its ledger entry is in the consolidated ledger PR #9673, not here.
What was unnecessary
- Weld:
mesh_weld's vertex key rounds fivef32components per vertex. Two of them are the constant0.0UV of an untextured mesh. - Orient: the weld grid in
mesh_orientrounds threef64coordinates per unique vertex. - Cost: on x86_64's baseline target and on wasm32, every
.round()is a call into libm. On main before this campaign's orient/weld change that was about 579M Ir on advanced_model and about 960M on Holter.
Change
grid::round_i32 and grid::round_i64 compute x.round() as i32 / as i64 inline: round half away from zero, saturating, NaN to 0. Below 2^23 (f32) or 2^52 (f64), x - trunc(x) is exact, so comparing it with ±0.5 decides the same rounding. At or above those magnitudes every value is already an integer, and the saturating cast alone is the answer.
They replace exactly two call sites: the weld vkey and the orient grid key, now a small grid_key helper so orient_mesh_outward_verdict stays within its function-length ratchet. No unsafe code, no new state.
Identity and tests
grid::testscompares both helpers bit for bit against libm: every 251stf32bit pattern (about 17M values, every exponent, NaN and infinities), 5M pseudo-randomf64values, and the edge cases (±0.5, ±2.5, 0.49999997, 2^23 − 0.5, 2^52 − 0.5, 2^63, MAX).- Revert-oracle observers in the existing
mesh_weld_tests.rsandmesh_orient_tests.rs. Test-only probes, bumped from the key code undercfg(test), show the work:- a 4-vertex weld performs 20 inline roundings;
- a 4-vertex tetrahedron's orient grid performs 12.
perf_probefingerprints are identical to main on all five fixtures (table below).
Qualification on Pop, by receipt, on this head b963faf50c merged with main 27ce7fc010. It covers what the merge queue runs, with the full CI fixture set: all 191 files of main's tests/models/manifest.json, fetched and verified.
- Clippy
-D warningsfor core, geometry and processing: clean. cargo test --workspace: pass. An earlier run on91556072f9failed onlyfunction_length_ratchet(190 lines against a budget of 185). That is fixed by extracting the helper, not by raising the budget.- Watertightness census (
--features triangulation-alt --test triangulation_invariance): pass. 0 regressed, 0 coverage loss, 0 added; void hosts 1,645 = 1,645. - Every step of
Rust tests (feature builds)passes: parquet-bos test and clippy, retained-browser test and clippy,rust/python, csg_manifold_gate test and clippy, geometry all-features clippy, csg_capture, and the three opening-perf-trace steps. cargo check --target wasm32-unknown-unknown -p ifc-lite-wasm: pass.- Revert oracle (
--ci, base = main): OBSERVED. With production reverted, orient fails 1 of 26 and weld fails 1 of 15.
Performance verdict
Cold, single-thread Callgrind via scripts/perf/instructions.sh (the --cold probe), measured against current main 27ce7fc010, which already contains #9632, #9635 and #9636. Each side built its own binary fresh. These are instruction counts only: no wall-time or browser-speed claim is made.
| Fixture | Phase | main 27ce7fc010 Ir | This PR Ir | Δ |
|---|---|---|---|---|
| FZK | Parse | 90,348,370 | 90,354,718 | +0.01% |
| FZK | Scan/prepass | 55,351,244 | 55,355,445 | +0.01% |
| FZK | Lookup | 11,739,672 | 11,739,954 | +0.00% |
| FZK | Preprocess | 23,169,740 | 23,171,605 | +0.01% |
| FZK | Geometry | 335,220,120 | 331,077,932 | -1.24% |
| FZK | Pipeline | 425,573,753 | 421,437,901 | -0.97% |
| advanced_model | Parse | 979,084,606 | 979,084,192 | -0.00% |
| advanced_model | Scan/prepass | 973,035,585 | 973,035,048 | -0.00% |
| advanced_model | Lookup | 229,983 | 229,983 | +0.00% |
| advanced_model | Preprocess | 5,678,733 | 5,678,856 | +0.00% |
| advanced_model | Geometry | 13,876,115,903 | 13,552,262,955 | -2.33% |
| advanced_model | Pipeline | 14,855,225,427 | 14,531,372,053 | -2.18% |
| schependomlaan | Parse | 1,417,728,376 | 1,417,801,386 | +0.01% |
| schependomlaan | Scan/prepass | 951,583,347 | 951,642,336 | +0.01% |
| schependomlaan | Lookup | 453,892,252 | 453,904,724 | +0.00% |
| schependomlaan | Preprocess | 9,034,396 | 9,035,945 | +0.02% |
| schependomlaan | Geometry | 2,147,669,704 | 2,099,986,887 | -2.22% |
| schependomlaan | Pipeline | 3,565,420,137 | 3,517,810,318 | -1.34% |
| ISSUE_129 | Parse | 256,881,396 | 256,883,275 | +0.00% |
| ISSUE_129 | Scan/prepass | 251,271,424 | 251,273,017 | +0.00% |
| ISSUE_129 | Lookup | 21,453 | 21,453 | +0.00% |
| ISSUE_129 | Preprocess | 5,458,353 | 5,458,639 | +0.01% |
| ISSUE_129 | Geometry | 25,467,824,550 | 25,430,818,682 | -0.15% |
| ISSUE_129 | Pipeline | 25,724,738,525 | 25,687,734,521 | -0.14% |
| Holter (holdout) | Parse | 4,896,910,656 | 4,897,129,610 | +0.00% |
| Holter (holdout) | Scan/prepass | 4,206,780,583 | 4,206,997,078 | +0.01% |
| Holter (holdout) | Lookup | 677,870,414 | 677,870,976 | +0.00% |
| Holter (holdout) | Preprocess | 5,172,852 | 5,174,749 | +0.04% |
| Holter (holdout) | Geometry | 22,296,388,578 | 21,746,525,438 | -2.47% |
| Holter (holdout) | Pipeline | 27,193,408,687 | 26,643,764,501 | -2.02% |
| Fixture | Meshes / vertices / triangles | Fingerprint main | Fingerprint this PR |
|---|---|---|---|
| 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 |
ISSUE_129's −0.14% is below the 1% gate on its own, but other fixtures clear it: advanced_model, Holter and schependomlaan by more than 1%, FZK by just under. No fixture rises.
This touches mesh_weld.rs and mesh_orient.rs, which #9635 also touched (merged). The hunks are disjoint, and main was merged in without conflicts. ci:native-adapter is requested because this is a geometry change.
🤖 Generated with Claude Code