Skip to content

[release-v2.0] main: Use backported rand updates.#3473

Merged
davecgh merged 2 commits intodecred:release-v2.0from
davecgh:rel20_crypto_rand_backports
Feb 20, 2025
Merged

[release-v2.0] main: Use backported rand updates.#3473
davecgh merged 2 commits intodecred:release-v2.0from
davecgh:rel20_crypto_rand_backports

Conversation

@davecgh
Copy link
Member

@davecgh davecgh commented Feb 20, 2025

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

Note that it also cherry picks all of the commits included in updates to the crypto/rand module to ensure they are also included in the release branch even though it is not strictly necessary since go.mod has 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 in go.work.

The following PRs are included:

jrick and others added 2 commits February 20, 2025 14:39
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
@davecgh davecgh added this to the 2.0.6 milestone Feb 20, 2025
@davecgh davecgh merged commit 8a7224d into decred:release-v2.0 Feb 20, 2025
2 checks passed
@davecgh davecgh deleted the rel20_crypto_rand_backports branch February 20, 2025 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants