Skip to content

Conversation

@waamm
Copy link

@waamm waamm commented Sep 14, 2025

Description

  • Consolidated duplicate functions: The previously separate functions msm_u8, msm_u16, msm_32, and msm_u64 have been replaced with a single generic function msm_small_int.
  • Edited the comment above msm_binary regarding its range.
  • Reduced the window size in msm_serial (it doesn't seem to have performance implications).

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (master)
  • Linked to GitHub issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests (not needed for small refactor)
  • Updated relevant documentation in the code (not needed for small refactor)
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md (not needed for small refactor)
  • Re-reviewed Files changed in the GitHub PR explorer

@waamm waamm requested review from a team as code owners September 14, 2025 18:50
@waamm waamm requested review from Pratyush, weikengchen and z-tech and removed request for a team September 14, 2025 18:50
@waamm waamm force-pushed the refactor-msm branch 3 times, most recently from 750b1f5 to 4daf283 Compare September 14, 2025 19:24

fn msm_u8<V: VariableBaseMSM>(mut bases: &[V::MulBase], mut scalars: &[u8]) -> V {
/// Generic MSM for small integer scalars.
fn msm_small_int_generic<V, S>(mut bases: &[V::MulBase], mut scalars: &[S]) -> V
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not call this one msm_u64? No point adding the word generic unless you're doing something strange.

Copy link
Author

Choose a reason for hiding this comment

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

I guess I'd prefer msm_small_int since this function is barely related to u64, but up to you?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've no real opinion aside from generic seemed redundent.

Copy link
Author

Choose a reason for hiding this comment

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

Ok I've renamed it (and replaced the invocations inside msm_signed). In hindsight, I'm not entirely sure this PR is timely as the code feels quite WIP: when I try a recent arkworks commit in my codebase instead of version 0.5.0, some functions using MSMs run a bit faster while others are much slower...

Copy link
Member

Choose a reason for hiding this comment

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

Hm I’d be interested to learn more about the cases where you experienced a slowdown; do you have a link?

Copy link
Member

Choose a reason for hiding this comment

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

Hm what machine are you running on? I wonder if some change happened to the underlying field arithmetic

Copy link
Author

Choose a reason for hiding this comment

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

The CPU is an M4 Max.

Copy link
Member

Choose a reason for hiding this comment

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

Hm I am also on a M3 CPU

Copy link
Author

Choose a reason for hiding this comment

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

I’ll try on an M1 later today or tomorrow and report back.

In the meantime, maybe this PR should be approved or closed and this discussion continued elsewhere?

Copy link
Author

@waamm waamm Oct 12, 2025

Choose a reason for hiding this comment

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

Similar results on an M1. (Again, this is for switching from 0.5.0 to your branch, where I had to modify std on this line to ark_std to get it to compile, executing env RAYON_NUM_THREADS=2 cargo bench --bench range_proof.)

Screenshot 2025-10-12 at 17 06 44

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.

3 participants