std.rand: Refactor Random
interface
#10045
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These changes have been made to fix the performance issues reported in issue #10037. The
Random
interface was implemented in such a way that it causes significant slowdown when calling thefill
function of the rng used. (reasoning is commented below the linked issue).The
Random
interface is no longer stored in a field of the rng, and is instead returned by the child functionrandom()
of the rng. This avoids the performance issues caused by the interface. These changes are breaking, and will break any code outside of Zig which depends upon it. There is no conceivable way to avoid this.cc: @SpexGuy
resolves #10037