Skip to content

perf(hex-poly-fast): remove Karatsuba traversal allocation - #9870

Merged
kim-em merged 1 commit into
mainfrom
issue-9744
Aug 31, 2026
Merged

perf(hex-poly-fast): remove Karatsuba traversal allocation#9870
kim-em merged 1 commit into
mainfrom
issue-9744

Conversation

@kim-em

@kim-em kim-em commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Closes #9744

Summary

  • replace per-diagonal List.range folds with allocation-free index loops while preserving the raw schoolbook specification
  • carry an offset through unbalanced Karatsuba block traversal so each block is copied once instead of copying every remaining suffix
  • retain proofs through ofCoeffs, benchmark both kernels against their former implementations, and synchronize the performance-report registry

Verification

  • lake build HexPolyFast.Karatsuba HexPolyFast.Conformance hexpolyfast_bench hexpolyfast_emit_fixtures
  • fresh conformance fixture output matches conformance-fixtures/HexPolyFast/polyfast.jsonl
  • oracle fallback checked all 120 emitted cases (local python-flint unavailable)
  • lake exe hexpolyfast_bench verify passes all 57 local targets; the seven FLINT-backed fixed targets fail only because python-flint is unavailable locally
  • Phase-4 headline/registration guard passes for all four new targets
  • focused warm-cache comparisons at n=1024: diagonal list 24.213 ms vs loop 7.457 ms; at 64:1 n=256: suffix-copy 114.626 ms vs offset 28.791 ms; paired hashes agree

Replace per-diagonal index lists with an allocation-free loop and carry an offset through unbalanced block traversal so each block is copied once. Preserve the Raw.ofCoeffs specifications and benchmark both kernels against their former implementations.

Cost model: both schoolbook comparators remain quadratic in balanced length n. At fixed 64:1 skew, both blocked comparators perform 64 Karatsuba products, so karatsubaCost n remains the tight model; the offset removes repeated suffix-copy constants.
@kim-em

kim-em commented Aug 31, 2026

Copy link
Copy Markdown
Owner Author

Fresh Claude Opus second opinion completed while CI was running.

Accepted and addressed:

  • made the retained old raw comparators generic over the same CommRing interface as production
  • normalized all four raw benchmark outputs through ofCoeffs before hashing
  • synchronized the performance-report registry and added the required explicit cost-model derivations

Independently verified: the source/proof chain is sound, Raw.ofCoeffs_schoolbook and Raw.ofCoeffs_blocks remain intact, and the named list/suffix allocations are removed.

Not expanded in this PR: a single mutable output buffer for addShift, a block-count scaling campaign, and narrowing the diagonal loop bounds. Those are broader/pre-existing optimization questions; #9744 specifically requests an allocation-free diagonal loop and offset-based block traversal, and no theorem or conformance obligation was weakened.

@kim-em
kim-em enabled auto-merge (squash) August 31, 2026 06:40
@kim-em
kim-em merged commit 31f058a into main Aug 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HexPolyFast: eliminate Karatsuba inner-loop and block-tail allocation

1 participant