Performance pass: nanobench migration, measured optimizations, wider gates#18
Merged
Conversation
…gates Benchmarking: replace ctrack with ankerl::nanobench (v4.3.11). One table per operation with the native implementation as first row, so the relative column reads directly as the bound-vs-native ratio; hardware perf counters (instructions/cycles/branch misses); constant memory (no print-and-clear workaround); cycling input pools instead of constant operands (which let both sides fold). New coverage: cross-grid assignment, comparison, casts, dot, ++, /=, store-from-double vs -fraction. `bench <md> [<json>]` writes the report; the perf_report target regenerates the committed docs/performance.md (same pattern as accuracy_report). Optimizations (measured before/after with the new bench, ins/op exact): - operator+= gets a point-bound fast branch: a just<v>/1_b rhs whose value is a whole number of notches adds a compile-time raw delta (encoding cancels every Lower term). ++/--: 76.8 -> 9.3 ns, 1255 -> 135 ins (8.3x); transform(v += 1_b): 100 -> 5.9 ns/elem (17x). - comparison: new integer value-index arm for same-notch integer-backed operands (compile-time bias + raw): 75.9 -> 11.7 ns, 1104 -> 225 ins. - abs_fraction: countr_zero shift instead of the per-bit strip loop — Q8.8 store from double halves (2532 -> 1266 ins); math::abs/floor ~1.6x. - fp add/mul skip the provably-dead snap_double (results are exact by construction under the double/float-exact gate) — docs/accuracy.md regenerates bit-identical. - to_fixed constants in sin/exp/log bound as constexpr locals (neutral at GCC -O3, guarantees the fold on MSVC/debug; matches the sqrt2_w pattern). - assign_op_result: nullopt from a reported failure leaves the value unchanged instead of dereferencing (robust under non-throwing handlers). The /= outer zero check stays: it carries the compound-form report semantics (binary / uses the nullopt vocabulary) and measured neutral. Gates: perf_workload gains key-selectable workloads (integer_qformat, integer_mul, qformat_div, cross_grid_assign, checked_add); check_perf.py passes the key to the binary; CI loops all keys (new baselines bootstrap on CI's gcc-14 via the existing arm-the-gate artifact flow). Codegen guard additionally asserts bnd_perf_mul_fast is call-free. Docs: generated docs/performance.md committed; README performance section reduced to headline ratios + link; stale fixed-point.md table removed. Verified: 429/429 ctest, 418/418 under BND_MATH_FIXED, fuzz clean on three seeds (~340M checks), accuracy tables bit-identical, codegen guard green, amalgamation regenerated, clang-tidy clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
AppleClang/libc++ does not provide <algorithm> transitively where libstdc++ does; abs_fraction's shared-factor shift now uses a ternary instead of pulling a new include into the core header. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The previous commit's amalgamation accidentally swept in local work-in-progress from detail/addition.hpp and detail/assignment.hpp that is not part of this PR. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Performance assessment + optimization pass. Full plan context: replace ctrack, document current state with generated tables, land only measured wins, widen the CI perf gates.
Benchmarking: ctrack → nanobench
relativecolumn reads directly as the bound-vs-native ratio. Hardware counters (ins/cyc/branch-miss) when the kernel allows.dot,++,/=, store-from-double vs store-from-fraction.perf_reporttarget regenerates the committed docs/performance.md (same pattern asaccuracy_report).Measured optimizations (ins/op exact; ns on the bench host)
++/--(new point-bound+=fast branch)transform(v += 1_b)per elementdouble(abs_fraction→countr_zero)math::abs/math::floorsnap_double)Honest non-wins, handled per the plan's revert rule: the
to_fixedconstexpr bindings measured neutral at GCC -O3 (kept — guarantees the fold on MSVC/debug, matches the existingsqrt2_wpattern); the/=outer-zero-check removal was reverted (it carries the compound-form report semantics; caught bytest_compound_assign). The relatedassign_op_resultnullopt guard stays as a robustness fix for non-throwing handlers.Wider CI gates
perf_workloadnow has 5 key-selectable deterministic workloads:integer_qformat(existing),integer_mul,qformat_div,cross_grid_assign,checked_add; the CI cachegrind step loops all keys. New keys bootstrap their baselines on this run (gcc-14 artifact flow, as with the original key) — review and commit the uploadedperf-baselineartifact to arm them.bnd_perf_mul_fast(four-quadrant integer multiply) is call-free at -O2.Docs
Generated
docs/performance.mdcommitted; README §Performance reduced to headline ratios + link;docs/fixed-point.md's stale (contradictory) table removed.Verification
429/429 ctest (unit, examples, compile-fail, amalgamate, codegen) · 418/418 under
BND_MATH_FIXED· fuzz clean on three seeds (~340 M property checks) ·docs/accuracy.mdregenerates bit-identical after the fp/cmath changes · clang-tidy clean under the CI filter · amalgamation regenerated.🤖 Generated with Claude Code