-
Notifications
You must be signed in to change notification settings - Fork 432
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
Future of SmallRng #767
Comments
Well reasoned. As I understand, micro-benchmarks of RNGs (especially of simple ones like PCG) are not all that representative of real-world usage. Additionally, my understanding is that SIMD instructions can have varying performance depending on CPU, power provision, thermal limits and use of hyperthreading, so a SIMD CSPRNG which can win micro-benchmarks on modern x86_64 CPUs does not make this the fastest option for everyone. All the same, I agree with the aim. Many users can switch to |
Benchmarks can be found here: https://bench.cr.yp.to/results-stream.html Notably, benchmarks for generating 8 bytes are included, where |
Encrypting an 8-byte message is quite a different application to, say, generating a boolean with Not really sure what your point is though, since we seem to agree on what we should do? (The first step being to optimise our ChaCha impl.) |
We are always generating a 64 byte block, where the ChaCha slow-down is less than 16 times, according to the benchmarks.
I guess the point is that we have to be careful about deprecating |
IIRC our advice on performance has always been roughly as follows: Is your last point about SIMD float operations? #269 is probably relevant here, but even more so the SIMD implementations for However, SIMD float operations are only useful operations for applications which can consume them; e.g. agent based sims & games would need agents to be batched and avoid most branching logic. This kind of optimisation wouldn't help everyone. |
There is another permutation that was designed to be smaller and faster for short messages than ChaCha: https://gimli.cr.yp.to It uses 384 bytes of state, so it is only 3 times larger than |
#792 introduced a feature-gate for |
Yes. Based on how much the feature is used, we can decide whether to keep it. |
SmallRng
is an RNG unsuitable for applications where unpredictable randomness is required, making it a poor default choice. There are currently two reasons to choose it overStdRng
:StdRng
, making it a suitable choice even for embedded applications. Remaining applications are massively parallel calculations, where the small state size might still be preferable, but this seems like a very niche use case that could be supported by a different crate.Once we use a good SIMD implementation of ChaCha, there are few use cases remaining where
SmallRng
would be preferable. I think we could remove it, which has the following advantages:rand
.rand
, requiring a more explicit opt-in to use a predictable RNG (by using an additional crate).Note that the current implementation of
StdRng
is significantly slower and larger thanSmallRng
, so I don't think we should deprecateSmallRng
just yet.The text was updated successfully, but these errors were encountered: