Implement faster thread local rng for scheduler
Implement optimal uniform random number generator using the method proposed in https://github.com/swiftlang/swift/pull/39143 based on OpenSSL's implementation of it in https://github.com/openssl/openssl/blob/1d2cbd9b5a126189d5e9bc78a3bdb9709427d02b/crypto/rand/rand_uniform.c#L13-L99
This PR also fixes some bugs found while developing it. This is a replacement for https://github.com/JuliaLang/julia/pull/50203 and fixes the issues found by @IanButterworth with both rngs
C rng
New scheduler rng
~On my benchmarks the julia implementation seems to be almost 50% faster than the current implementation.~ With oscars suggestion of removing the debiasing this is now almost 5x faster than the original implementation. And almost fully branchless
We might want to backport the two previous commits since they technically fix bugs.
Hmm, this seems to have made i686 very unhappy. Ok the issue is that pointer load. 32 bit has different alignment which is what is blowing this up
We might want to backport the two previous commits since they technically fix bugs.
Sounds like that should be a separate PR
Potentially naive question, but do we have a good benchmark to demonstrate that a faster scheduler rng actually speeds up scheduling?
I ask because in my testing of https://github.com/JuliaLang/julia/pull/50203 I saw the surprising behavior that the threaded fib got slower the faster the rng used (with no changes to allocations)
function fib(n::Int)
n < 2 && return n
t = Threads.@spawn fib(n - 2)
return fib(n - 1) + fetch(t)
end
I don't think it will affect it too too much. Because if the rand call is super hot then things aren't going so well elsewhere :)
There are already merge conflicts
@nanosoldier runtests(ALL, vs = ":master")
The package evaluation job you requested has completed - possible new issues were detected. The full report is available.
Do we need to run benchmarks, too?
I don't think any benchmark is gonna show this. At least no current one. Calling the function is 5x faster that's all I can say