Skip to content

Improve performance of MSMPrecompWindowSigned::mul - #107

Open
psalz wants to merge 1 commit into
crate-crypto:masterfrom
psalz:improve-msm-precomp-performance
Open

psalz wants to merge 1 commit into
crate-crypto:masterfrom
psalz:improve-msm-precomp-performance

Conversation

@psalz

@psalz psalz commented Jan 21, 2026

Copy link
Copy Markdown

This improves the performance of MSMPrecompWindowSigned::mul in cases where many of the scalars are zero. This is achieved by switching the loop order, adding an early exit condition and avoiding unnecessary allocations. Committing to only a few or even a single non-zero value is frequently needed when doing incremental updates on commitments, for example when updating a single value of a Verkle trie leaf.

I added a benchmark to exercise this, for which on my machine I see a 28% improvement:

msm precomp 16 single idx: 3
                        time:   [1.3312 µs 1.3536 µs 1.3787 µs]
                        change: [-29.653% -28.399% -27.165%] (p = 0.00 < 0.05)
                        Performance has improved.

The performance of committing to all non-zero values remains unaffected.

This improves the performance of MSMPrecompWindowSigned::mul in cases
where many of the scalars are zero.
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