diff options
| author | Gavin Lam <gavin.oss@tutamail.com> | 2026-01-23 03:44:50 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2026-01-23 14:41:52 -0800 |
| commit | 27fcec4d8f3041e845762303d85d868cc3e351e8 (patch) | |
| tree | d1e01667e89ba83ddf89296a22921b2e39f76b04 /src/runtime/runtime2.go | |
| parent | 478d86446e88dc9e0b46e08914cb564d7c705d1e (diff) | |
| download | go-27fcec4d8f3041e845762303d85d868cc3e351e8.tar.xz | |
runtime: speed up cheaprand and cheaprand64
The current cheaprand performs 128-bit multiplication on 64-bit numbers
and truncate the result to 32 bits, which is inefficient.
A 32-bit specific implementation is more performant because it performs
64-bit multiplication on 32-bit numbers instead.
The current cheaprand64 involves two cheaprand calls.
Implementing it as 64-bit wyrand is significantly faster.
Since cheaprand64 discards one bit, I have preserved this behavior.
The underlying uint64 function is made available as cheaprandu64.
│ old │ new │
│ sec/op │ sec/op vs base │
Cheaprand-8 1.358n ± 0% 1.218n ± 0% -10.31% (n=100)
Cheaprand64-8 2.424n ± 0% 1.391n ± 0% -42.62% (n=100)
Blocksampled-8 8.347n ± 0% 2.022n ± 0% -75.78% (n=100)
Fixes #77149
Change-Id: Ib0b5da4a642cd34d0401b03c1d343041f8230d11
GitHub-Last-Rev: 549d8d407e2bbcaecdee0b52cbf3a513dda637fb
GitHub-Pull-Request: golang/go#77150
Reviewed-on: https://go-review.googlesource.com/c/go/+/735480
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime/runtime2.go')
| -rw-r--r-- | src/runtime/runtime2.go | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index be33932b24..bf47955d0d 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -715,8 +715,9 @@ type m struct { mOS - chacha8 chacha8rand.State - cheaprand uint64 + chacha8 chacha8rand.State + cheaprand uint32 + cheaprand64 uint64 // Up to 10 locks held by this m, maintained by the lock ranking code. locksHeldLen int |
