Skip to content

perf: cache the Bulletproofs generators instead of rebuilding them per call - #1013

Merged
jonas-lj merged 1 commit into
mainfrom
jonas/bp-cache-generators
Aug 27, 2026
Merged

perf: cache the Bulletproofs generators instead of rebuilding them per call#1013
jonas-lj merged 1 commit into
mainfrom
jonas/bp-cache-generators

Conversation

@jonas-lj

@jonas-lj jonas-lj commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

prove_batch and verify_batch rebuilt BulletproofGens on every call. This PR caches them on first use.

Verification benchmarks:

Config before after speedup
16-bit x4 2.12 1.34 1.6x
16-bit x8 3.86 1.92 2.0x
16-bit x16 7.98 3.63 2.2x
16-bit x32 13.37 5.58 2.4x

@jonas-lj
jonas-lj marked this pull request as ready for review August 27, 2026 13:24
@jonas-lj
jonas-lj requested review from Daeinar and benr-ml August 27, 2026 13:24
…r call

`prove_batch` and `verify_batch` called `BulletproofGens::new(bits, m)` on
every invocation, which dominated both operations: at 64-bit x32 the build
alone costs ~32 ms against ~17 ms of actual verification.

The generators are prefix stable in both dimensions, so a single oversized
instance serves every configuration and yields byte-identical proofs. `Range`
caps the bit width at 64, so only the batch size can exceed the cached object;
larger batches keep building generators per call as before.

No API or wire-format change.
@jonas-lj
jonas-lj force-pushed the jonas/bp-cache-generators branch from ca7e18a to 151e363 Compare August 27, 2026 13:31

@Daeinar Daeinar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jonas-lj
jonas-lj merged commit 12663dc into main Aug 27, 2026
9 checks passed
@jonas-lj
jonas-lj deleted the jonas/bp-cache-generators branch August 27, 2026 16: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.

2 participants