Skip to content

perf(dory): cache affine G1 bases for streaming commitment#1393

Open
mw2000 wants to merge 2 commits intoa16z:mainfrom
mw2000:perf/dory-affine-g1-cache
Open

perf(dory): cache affine G1 bases for streaming commitment#1393
mw2000 wants to merge 2 commits intoa16z:mainfrom
mw2000:perf/dory-affine-g1-cache

Conversation

@mw2000
Copy link
Copy Markdown
Contributor

@mw2000 mw2000 commented Apr 1, 2026

process_chunk and process_chunk_onehot convert the same G1 generators from projective to affine form on every call — once per row of the streaming commitment. For a typical proof this happens hundreds of times, each incurring a batch field inversion that produces the same result.

This PR caches the affine G1 bases in a module-level RwLock<Vec<G1Affine>>, initialized once during setup_prover via G1Projective::normalize_batch. Subsequent calls read from the cache with no conversion overhead. The cache is cleared in reset() for test isolation, and affine_g1_bases_or_init() provides lazy initialization as a fallback.

Also removes the unsafe from_raw_parts pointer aliasing that was previously used to access the G1 slice.

@mw2000 mw2000 requested a review from markosg04 as a code owner April 1, 2026 19:42
@mw2000 mw2000 marked this pull request as draft April 1, 2026 20:12
@mw2000 mw2000 marked this pull request as ready for review April 2, 2026 14:11
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.

1 participant