[release-v2.0] main: Use backported rand updates.#3473
Merged
davecgh merged 2 commits intodecred:release-v2.0from Feb 20, 2025
Merged
[release-v2.0] main: Use backported rand updates.#3473davecgh merged 2 commits intodecred:release-v2.0from
davecgh merged 2 commits intodecred:release-v2.0from
Conversation
On Go 1.24, the standard library crypto/rand.Read method will read
cryptographically secure bytes using arc4random_buf(3) instead of
getentropy(2). This avoids a context switch to kernel for a system call and
is much faster on small reads than both the previous stdlib crypto/rand
reader, and our custom implemented userspace PRNG. It also avoids the need to
provide (additional) locking to the dcrd's package global userspace PRNG.
goos: openbsd
goarch: amd64
pkg: github.com/decred/dcrd/crypto/rand
cpu: AMD Ryzen 7 5800X3D 8-Core Processor
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
DcrdRead/4b-8 149.7n ± 1% 124.3n ± 1% -16.91% (p=0.000 n=10)
DcrdRead/8b-8 163.8n ± 0% 137.8n ± 1% -15.84% (p=0.000 n=10)
DcrdRead/32b-8 243.9n ± 1% 232.2n ± 2% -4.82% (p=0.001 n=10)
DcrdRead/512b-8 1.460µ ± 0% 1.814µ ± 0% +24.25% (p=0.000 n=10)
DcrdRead/1KiB-8 2.770µ ± 0% 3.501µ ± 3% +26.39% (p=0.000 n=10)
DcrdRead/4KiB-8 10.50µ ± 1% 13.55µ ± 4% +29.06% (p=0.000 n=10)
StdlibRead/4b-8 519.5n ± 1% 124.1n ± 0% -76.11% (p=0.000 n=10)
StdlibRead/8b-8 534.5n ± 1% 137.9n ± 1% -74.20% (p=0.000 n=10)
StdlibRead/32b-8 624.3n ± 2% 231.9n ± 1% -62.86% (p=0.000 n=10)
StdlibRead/512b-8 2.631µ ± 0% 1.816µ ± 0% -30.98% (p=0.000 n=10)
StdlibRead/1KiB-8 5.196µ ± 0% 3.494µ ± 0% -32.76% (p=0.000 n=10)
StdlibRead/4KiB-8 20.52µ ± 0% 13.52µ ± 0% -34.12% (p=0.000 n=10)
DcrdReadPRNG/4b-8 140.6n ± 0% 124.1n ± 0% -11.74% (p=0.000 n=10)
DcrdReadPRNG/8b-8 154.9n ± 0% 137.2n ± 1% -11.43% (p=0.000 n=10)
DcrdReadPRNG/32b-8 228.8n ± 0% 232.0n ± 0% +1.42% (p=0.001 n=10)
DcrdReadPRNG/512b-8 1.423µ ± 0% 1.816µ ± 0% +27.54% (p=0.000 n=10)
DcrdReadPRNG/1KiB-8 2.721µ ± 0% 3.496µ ± 0% +28.49% (p=0.000 n=10)
DcrdReadPRNG/4KiB-8 10.45µ ± 0% 13.52µ ± 0% +29.35% (p=0.000 n=10)
Int32N-8 174.4n ± 1% 148.4n ± 0% -14.88% (p=0.000 n=10)
Uint32N-8 173.6n ± 1% 147.0n ± 0% -15.32% (p=0.000 n=10)
Int64N-8 170.9n ± 1% 146.1n ± 0% -14.48% (p=0.000 n=10)
Uint64N-8 170.4n ± 0% 145.9n ± 1% -14.40% (p=0.000 n=10)
Duration-8 191.1n ± 7% 159.0n ± 10% -16.80% (p=0.000 n=10)
ShuffleSlice-8 161.5n ± 0% 144.6n ± 1% -10.50% (p=0.000 n=10)
geomean 670.3n 542.5n -19.07%
This updates the 2.0 release branch to use the latest version of the crypto/rand module which includes performance enhancements for OpenBSD. In particular, the following updated module version is used: - github.com/decred/dcrd/crypto/rand@v1.0.1
jrick
approved these changes
Feb 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This updates the 2.0 release branch to use the latest version of the
crypto/randmodule which includes performance enhancements for OpenBSD.In particular, the following updated module version is used:
Note that it also cherry picks all of the commits included in updates to the
crypto/randmodule to ensure they are also included in the release branch even though it is not strictly necessary sincego.modhas been updated to require the new release and thus will pull in the new code. However, from past experience, not having code backported to modules available in the release branch too leads to headaches for devs building from source in their local workspace with overrides such as those ingo.work.The following PRs are included: