-
-
Notifications
You must be signed in to change notification settings - Fork 433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve SmallRng initialization performance #1482
Improve SmallRng initialization performance #1482
Conversation
examples/smallrng-code-gen.rs
Outdated
@@ -0,0 +1,45 @@ | |||
extern crate rand; | |||
use std::hint::black_box; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the min MSRV is problematic here, maybe this will have to be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either that, or...
This example serves as a non-automated test to check code generation? Can we turn it into an automated test? Otherwise I suggest it just be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is just an optimisation which does not change any results?
examples/smallrng-code-gen.rs
Outdated
@@ -0,0 +1,45 @@ | |||
extern crate rand; | |||
use std::hint::black_box; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either that, or...
This example serves as a non-automated test to check code generation? Can we turn it into an automated test? Otherwise I suggest it just be removed.
Reminder: changes are needed to ensure the API remains consistent on 32-bit and 64-bit platforms. Also, these new benchmarks can't be merged since #1490 moved all benchmarks to use Criterion. |
6224cfb
to
ae6ef7a
Compare
Rebased on |
ae6ef7a
to
5410c5d
Compare
CI seems unhappy about a file I didn't change, not sure what's up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor 'bug'; otherwise looks good.
src/rngs/xoshiro128plusplus.rs
Outdated
i[0] = z.to_le() as u32; | ||
i[1] = (z.to_le() >> 32) as u32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We aren't round-tripping to LE bytes and back since your code now directly initializes state, hence we don't want .to_le()
here.
This should trip a test, but it seems we never actually test seed_from_u64
... because we don't guarantee value-stability for SmallRng
anyway. (In other words, this isn't strictly a bug, but you should still remove .to_le()
, and preferably also add some form of reference test for this method.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remove it, won't the result be different than before on BE? I was trying to preserve that here. But yeah, kinda pointless w/o a test to ensure that it's correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that this PR should add test for the expected state of the Rng after seed_from_u64
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a reference
test in the same file, but in this case testing a single sample should be enough. And yes, results should match from prior to your PR.
It doesn't really matter since we explicitly do not promise value stability of these RNGs, but feel like we should anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
CHANGELOG.md
entrySummary
Improve initialization speed for SmallRng
Motivation
SmallRng
is plenty fast, but the initialization speed was suboptimal.Details
An example binary was added to check for code generation with
cargo asm
.Benchmarks were also added. The results are shown below: