-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Implementation of Lemire's nearly divisionless method #79790
Conversation
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/area-system-runtime Issue Details
|
Could you please add benchmark(s) to dotnet/performance so we protect your work when it goes in? Or is coverage good enough already? |
Which numbers or intervals to pick for benchmarks decides which algorithm is "optimal". IMO it could be interesting to include the edge cases: |
src/libraries/System.Private.CoreLib/src/System/Random.Xoshiro128StarStarImpl.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Random.Xoshiro128StarStarImpl.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Random.Xoshiro256StarStarImpl.cs
Outdated
Show resolved
Hide resolved
/benchmark microbenchmarks aspnet-perf-win runtime --variable filter=System.Tests.Perf_Random* |
Benchmark started for microbenchmarks on aspnet-perf-win with runtime and arguments |
microbenchmarks - aspnet-perf-win
| benchmark | mean (microbenchmarks.base) | mean (microbenchmarks.pr) | ratio | allocated (microbenchmarks.base) | allocated (microbenchmarks.pr) | ratio |
| ----------------------- | --------------------------- | ------------------------- | ----- | -------------------------------- | ------------------------------ | ----- |
| ctor | 80.83 ns | 81.42 ns | 1.01 | 72 B | 72 B | 1.00 |
| ctor_seeded | 291.5 ns | 292.1 ns | 1.00 | 304 B | 304 B | 1.00 |
| Next | 7.939 ns | 8.179 ns | 1.03 | 0 B | 0 B | |
| Next_int | 8.980 ns | 9.050 ns | 1.01 | 0 B | 0 B | |
| Next_int_int | 9.059 ns | 9.905 ns | 1.09 | 0 B | 0 B | |
| Next_int_int_unseeded | 7.311 ns | 2.102 ns | 0.29 | 0 B | 0 B | |
| Next_int_unseeded | 7.443 ns | 2.261 ns | 0.30 | 0 B | 0 B | |
| Next_long | 37.09 ns | 35.41 ns | 0.95 | 0 B | 0 B | |
| Next_long_long | 37.65 ns | 39.01 ns | 1.04 | 0 B | 0 B | |
| Next_long_long_unseeded | 8.304 ns | 2.659 ns | 0.32 | 0 B | 0 B | |
| Next_long_unseeded | 4.268 ns | 2.549 ns | 0.60 | 0 B | 0 B | |
| Next_unseeded | 1.844 ns | 1.746 ns | 0.95 | 0 B | 0 B | |
| NextBytes | 5.3 μs | 5.6 μs | 1.05 | 0 B | 0 B | |
| NextBytes_span | 5.5 μs | 5.6 μs | 1.01 | 0 B | 0 B | |
| NextBytes_span_unseeded | 119.1 ns | 118.8 ns | 1.00 | 0 B | 0 B | |
| NextBytes_unseeded | 119.1 ns | 119.0 ns | 1.00 | 0 B | 0 B | |
| NextDouble | 7.980 ns | 7.980 ns | 1.00 | 0 B | 0 B | |
| NextDouble_unseeded | 1.991 ns | 1.961 ns | 0.98 | 0 B | 0 B | |
| NextSingle | 7.995 ns | 7.999 ns | 1.00 | 0 B | 0 B | |
| NextSingle_unseeded | 2.000 ns | 1.977 ns | 0.99 | 0 B | 0 B | | |
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.
The implementation and 64-bit perf look good. I'm building locally for 32-bit to check that.
On 32-bit, I get numbers like this:
So, at least according to these benchmarks, this PR represents a potential regression on 32-bit, in particular for NextInt64. Can you measure on 32-bit as well, @mla-alm? |
I am running on Linux, so cannot measure on 32-bit.
Maybe it is better to be conservative and leave the implementation (at least the NextInt64) as is in Xoshiro128? |
@stephentoub What do you think about that idea? |
Yeah, let's leave the Xoshiro128's NextInt64 unmodified for now, other than a comment indicating why it's not getting the same treatment as the others. |
Xoshiro128's NextInt64 is as it was before. And comment added. |
src/libraries/System.Private.CoreLib/src/System/Random.Xoshiro128StarStarImpl.cs
Outdated
Show resolved
Hide resolved
…128StarStarImpl.cs
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!
@mla-alm Thank you! Perhaps you'd be interested in another contribution somewhere? |
Improvements on x64 dotnet/perf-autofiling-issues#13151 |
Hi @danmoseley. |
Improvements on win-x64: |
See your perf win confirmed above! In terms of what to take on next -- any issue that's help wanted (or possibly others) https://github.com/dotnet/runtime/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22 if you have a particular area you're interested in, you could ask them https://github.com/dotnet/runtime/blob/main/docs/area-owners.md or ask here or in discussions. we are always happy to have new regular contributors. |
#75395