Performance: field-op counts + batched group law + smalljac comparison - #2
Merged
Conversation
Add an instrumented `CountingField` and a reproducible test that reports the generic-branch degree-2 add/double field-operation counts for each variant (run: cargo test --release g2::split::op_counts -- --nocapture). The test asserts each group operation uses exactly one field inversion (affine formula invariant). README documents the table; these counts are the field-size- independent metric for comparing against Lange / Erickson-Jacobson-Stein / Costello-Lauter.
Add a ~56-bit prime instantiation to the ramified not_char2 benchmarks and a reproducible C harness (benches/smalljac-compare/) that times smalljac's genus-2 imaginary group law (hecurve_g2_compose/square) on the affine path. At matched field width the crate's degree-2-specialized explicit formulas (~741/682 ns add/double) run about 2x faster than smalljac's general composition (~1470/1619 ns); at 16-bit the gap is wider but unfair, since ff_poly always uses 57-bit Montgomery arithmetic. Document the numbers and the (field-width, batched-inversion, specialized-vs-general) caveats in the README, alongside the field-operation-count table.
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.
Follow-up to #1 (genus-2 split model). Performance characterization + a new batched group law. No changes to the existing scalar formulas.
1. Field-operation counts (
e7d6d4a)src/g2/split/op_counts.rs: aCountingFieldwrapper that runs the realadd/doubleformulas and tallies M/S/I/A (the field-size-independent metric from Lange / Erickson–Jacobson–Stein / Costello–Lauter). Asserts exactly one inversion per op. Table in README.2. Batched group law — Montgomery simultaneous inversion (
846c258)field::batch_invert— one field inversion + ~3(n−1) mults for a whole slice.g2::ramified::not_char2: two-phase split of the generic deg-2 add/double (deg2_add_pre/deg2_add_post, …) +add_batch/double_batchdrivers that amortize the single inversion across a batch. Mirrors smalljac'sctx+ff_parallel_invertpath.3. smalljac wall-clock comparison — scalar + batched (
752c87b,a545959)Built smalljac v4.1.3 + ff_poly v1.2.7 on arm64 (
benches/smalljac-compare/, harness only — smalljac/ff_poly not vendored, GPL).Corrected, same-machine results (ns per op):
Batching helps both (removes the inversion): crate 56-bit add 673→348 (1.9×), smalljac 190→48 (4×). smalljac is faster in every cell, and the reason is the field layer, not the genus-2 formulas (op counts match): at 56-bit, multiply 8.2 ns (crate) vs 4.5 ns (smalljac, Montgomery), inversion 529 ns vs 157 ns. Closing the gap is a Montgomery-
PrimeFieldtask, not a formula one. Full table + analysis in the README.Checks
cargo fmt --check,cargo +stable clippy --all-targets -- -D warnings,cargo test --release(228 + doctest),cargo bench --no-run,cargo docall green.