perf(geometry): run incircle stages C and D without zeroing 18 KB per call
Self-driven work from the native instruction-count hillclimb (campaign 2), so no issue; labelled unqueued.
What was unnecessary
#9016 runs stages A and B of the in-circle test with right-sized scratch. It hands whatever stage B cannot decide to geometry_predicates::incircle, on the assumption that this path is rare. It is not rare. On ISSUE_129, 43,331 calls reach incircleadapt, costing 1.03G Ir, and about 78% of that (806M) is a memset. incircleadapt zeroes about 20 KB of scratch on every call, 18 KB of it the two 1152-entry fin expansions, although every read of those stays inside the prefix the same call wrote. FZK spends 21.6M Ir (about 5% of its pipeline) on the same path. From the call graph, most of these calls go on into stage D: about 7.6 extra expansion scalings per call.
Change
stage_b now hands back its own state (the stage-B expansion, the differences and their tails, the three 2×2 minors) instead of the call being redone by the crate. The new cdt/incircle_tail.rs continues from that state through stage C and stage D. It is a port of incircleadapt that uses the crate's public expansion routines with the same operands in the same order, so it returns the same f64 bits.
The two fin buffers are this thread's reused scratch (fixed at 2 × 1152 f64, allocated once, and never re-zeroed). That is safe because they are only read below the length the same call wrote. Every other buffer is still zeroed per call, exactly as in the crate, because the crate reads past a written prefix in two places, and the port keeps both:
- the
bct/cat/abtdefaults of length 1; cxtab, whose length the crate shadows and therefore reads as 8.
There is no unsafe code. The per-thread scratch is fixed at 18 KB.
For review: licence provenance. incircle_tail.rs follows geometry-predicates 0.3.0's incircleadapt operation for operation. That crate is MIT-licensed (© 2017 Egor Larionov, a port of Shewchuk's public-domain predicates), so the file header carries its copyright line. Please confirm that MIT-derived code in this file is acceptable. The alternative would be upstreaming the fix to the crate.
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. Measured: commit 274692c5aa alone (main plus this one commit), against the main baseline. (An earlier revision of this body showed #9636's table by mistake; corrected.)
| Fixture | Phase | Before Ir | After Ir | Δ |
|---|---|---|---|---|
| FZK | Parse | 90,464,330 | 90,448,252 | -0.02% |
| FZK | Scan/prepass | 55,377,490 | 55,364,171 | -0.02% |
| FZK | Lookup | 11,766,550 | 11,767,731 | +0.01% |
| FZK | Preprocess | 23,232,378 | 23,228,438 | -0.02% |
| FZK | Geometry | 342,404,967 | 323,771,226 | -5.44% |
| FZK | Pipeline | 432,874,522 | 414,224,735 | -4.31% |
| advanced_model | Parse | 979,435,806 | 979,168,792 | -0.03% |
| advanced_model | Scan/prepass | 973,349,199 | 973,082,009 | -0.03% |
| advanced_model | Lookup | 229,983 | 229,983 | +0.00% |
| advanced_model | Preprocess | 5,716,130 | 5,716,325 | +0.00% |
| advanced_model | Geometry | 17,165,943,981 | 17,149,841,494 | -0.09% |
| advanced_model | Pipeline | 18,145,404,666 | 18,129,035,231 | -0.09% |
| schependomlaan | Parse | 1,418,372,532 | 1,418,319,057 | -0.00% |
| schependomlaan | Scan/prepass | 951,772,820 | 951,674,044 | -0.01% |
| schependomlaan | Lookup | 454,306,360 | 454,354,136 | +0.01% |
| schependomlaan | Preprocess | 8,760,859 | 9,072,290 | +3.55% |
| schependomlaan | Geometry | 2,294,618,638 | 2,294,572,718 | -0.00% |
| schependomlaan | Pipeline | 3,713,013,248 | 3,712,913,859 | -0.00% |
| ISSUE_129 | Parse | 257,065,408 | 256,983,700 | -0.03% |
| ISSUE_129 | Scan/prepass | 251,436,897 | 251,356,754 | -0.03% |
| ISSUE_129 | Lookup | 21,453 | 21,453 | +0.00% |
| ISSUE_129 | Preprocess | 5,476,728 | 5,475,153 | -0.03% |
| ISSUE_129 | Geometry | 25,630,362,629 | 24,764,312,289 | -3.38% |
| ISSUE_129 | Pipeline | 25,887,460,470 | 25,021,328,614 | -3.35% |
| Holter (holdout) | Parse | 4,897,361,125 | 4,897,354,193 | -0.00% |
| Holter (holdout) | Scan/prepass | 4,207,203,960 | 4,207,133,491 | -0.00% |
| Holter (holdout) | Lookup | 677,871,380 | 677,933,492 | +0.01% |
| Holter (holdout) | Preprocess | 5,197,694 | 5,200,199 | +0.05% |
| Holter (holdout) | Geometry | 25,000,452,946 | 24,880,435,109 | -0.48% |
| Holter (holdout) | Pipeline | 29,897,921,942 | 29,777,897,956 | -0.40% |
| 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. #9632, #9635 and #9636, which share no code with this change, show the same rise, so it comes from the measurement run, not from this change.
Identity and tests
- The existing
incircle_matches_geometry_predicates_bit_for_bit_issue_9016now exercises the port. It compares bits againstgeometry_predicates::incircleon every path: generic inputs, lattice-cocircular inputs, collinear constraints, more than 1,000 ulp-nudged stage-C/D cases, near-cocircular inputs in the stage-B error-bound band, extreme magnitudes, and non-finite inputs. Passes. All 15cdtunit tests pass, as doescargo clippy -p ifc-lite-geometry --all-targets -- -D warnings. perf_probefingerprints are identical on all five fixtures (table above), and so is ISSUE_129'scsgFailurescount (9 = 9).- Still pending (queued on Pop, results will be added here): clippy
-D warningsfor core, geometry and processing; fullcargo testofifc-lite-core,ifc-lite-geometryandifc-lite-processingon the 121-model corpus (census, golden,mesh_determinism); theexport_goldentest;cargo check --target wasm32-unknown-unknown -p ifc-lite-wasm.
This is independent of #9632, #9635 and #9636 (no shared code), and is a separate branch off main. Ledger entry added under "Shipped wins". ci:native-adapter is requested because this is a geometry change.
🤖 Generated with Claude Code