perf: Dory/pairing micro-optimizations#87
Merged
Conversation
Three independent changes targeting pairing and GLV scalar mul: 1. Increase MAX_PREPARED_BATCH from 16 to 64 — shares one Fp12.square() across 64 pairs instead of 4 sub-batches of 16. 2. Combine dbl+add lines in batchedMillerLoopUnprepared — at non-zero ATE bits, use fp12Mul034By034 + fp12MulBy01234 (23 Fp2.mul) instead of two separate fp12MulBy034 calls (26 Fp2.mul). Matches the pattern already used in batchedMillerLoopPreparedSparse. 3. Precomputed 16-entry Shamir table for GLV 4D scalar mul — replaces up to 4 individual addAffine calls per bit with a single table lookup and addAffine. Median benchmark (3 runs, sha256_2048): Baseline: 2663 ms → Optimized: 2599 ms (~2.4% improvement) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
MAX_PREPARED_BATCHfrom 16 to 64 — shares oneFp12.square()across 64 pairs instead of 4 sub-batches of 16batchedMillerLoopUnprepared— usesfp12Mul034By034+fp12MulBy01234(23 Fp2.mul) instead of two separatefp12MulBy034(26 Fp2.mul), matchingbatchedMillerLoopPreparedSparseaddAffineper bit with a single table lookupBenchmark (sha256_2048, 3-run median)
Test plan
zig build test -Doptimize=ReleaseFast— all tests passbench/run-bench.sh sha256_2048— proof verified, no regression🤖 Generated with Claude Code