Skip to content

Conversation

@apoelstra
Copy link
Collaborator

The div_mod_128_64 jet has preconditions and shortcuts its operation if these are not met. To benchmark correctly we need to sample according to those preconditions.

@apoelstra apoelstra force-pushed the 2025-11/benchmark-divmod branch 2 times, most recently from f7adad0 to 0f6cf69 Compare November 21, 2025 22:25
@apoelstra apoelstra marked this pull request as ready for review November 21, 2025 22:41
Copy link
Collaborator Author

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

On 0f6cf69 successfully ran local tests

@apoelstra
Copy link
Collaborator Author

The new distribution is consistently slower than the uniform one. But all results are in a 40-60ns range; I see maybe a 10% slowdown rather than the 2x (or maybe 4x) that I would naively expect.

But I added printfs to the C code to confirm that with the new distribution we are no longer hitting the "shortcut" case, while with the uniform distribution we are. So this is working. I think this is just a case where the marshalling cost is overwhelming the actual computation cost.


// To implement this, we sample two random 64-bit strings, with one of them
// having its high bit forced to 1. The higher of the two (which will always
// have its high bit 1) is ah, and the other one is b.
Copy link
Contributor

Choose a reason for hiding this comment

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

The higher of the two is b.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@apoelstra apoelstra force-pushed the 2025-11/benchmark-divmod branch from 0f6cf69 to 9dc53e8 Compare November 21, 2025 22:59
}
unreachable!("if we get here, two uniform 63-bit samples were exactly equal")
} else {
panic!("invalid distribution {} for BIP 340 signature", dist)
Copy link
Contributor

Choose a reason for hiding this comment

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

Bad message.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@apoelstra apoelstra force-pushed the 2025-11/benchmark-divmod branch from 9dc53e8 to 8cb7e03 Compare November 21, 2025 23:02
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