Skip to content

internal/runtime/maps: hash small keys with wyhash instead of AES - #80895

Open
mcy wants to merge 2 commits into
golang:masterfrom
mcy:mcy/aes-cutoff
Open

internal/runtime/maps: hash small keys with wyhash instead of AES#80895
mcy wants to merge 2 commits into
golang:masterfrom
mcy:mcy/aes-cutoff

Conversation

@mcy

@mcy mcy commented Aug 16, 2026

Copy link
Copy Markdown

Replace UseAeshash with MinAeshashSize, which sets the smallest key size
at which we actually use AES hash. This tunable parameter can be
discovered using benchmarks, allowing for fine-tuning of a hybrid
wyhash/AES implementation to different microarchitectures.

It turns out that using AES for very small keys leaves a noticeable
amount of performance on the table, because SIMD instructions do not
like being used for one-offs. Unsurprisingly, the a block cipher wants
streaming inputs.

This CL includes a benchmark that can be used to calculate ideal cutoff
values for other targets. I've used the Zen 4 x86_64 implementtion for
this particular CL, but preparing similar changes keyed on stepping
numbers (e.g. to target Intel chips) should be a very easy and
worthwhile followup.

On my machine (Zen4, 7995WX), I selected the cutoff at 8 bytes, and
observed the following improvements across multiple linker-randomized
binaries:

HashInt64Speed                        4.79n  4.31n  -10.0%
MapAccessHit/int64/len=64             5.23n  4.91n   -6.0%
MapAccessHit/int64/len=65536          8.37n  7.80n   -6.8%
MapAccessMiss/int64/len=65536         7.75n  6.98n  -10.9%
MapAssignExists/int64/len=6           6.39n  5.70n  -10.7%
MapAccessHit/string/len=65536         12.3n  11.8n   -5.2%
MapAccessHit/int64/len=6              3.60n  3.60n    ~
GroupByInt64 (1M-row aggregation)     7.46m  6.38m  -14.6%

The final benchmark is new, and is intended to measure hash latency
specifically; existing benchmarks look good on AES because they focus on
throughput.

All other benchmarks do not show statistically significant changes as
reported by benchstat.

@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 7a2e155) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/815960.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/815960.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Keith Randall:

Patch Set 2:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/815960.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Sunny Young de la Sota:

Patch Set 2:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/815960.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Keith Randall:

Patch Set 3: Auto-Submit+1 Code-Review+2 Commit-Queue+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/815960.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 3:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2026-08-17T21:17:28Z","revision":"fb52a28ee042aca8cf958e4d2404ae735ee2ab9d"}


Please don’t reply on this GitHub thread. Visit golang.org/cl/815960.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Keith Randall:

Patch Set 3: Code-Review+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/815960.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Keith Randall:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/815960.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Keith Randall:

Patch Set 3: -Commit-Queue

(Performed by <GERRIT_ACCOUNT_60063> on behalf of <GERRIT_ACCOUNT_5200>)


Please don’t reply on this GitHub thread. Visit golang.org/cl/815960.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 3:

This CL has passed the run


Please don’t reply on this GitHub thread. Visit golang.org/cl/815960.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 3: LUCI-TryBot-Result+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/815960.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Sunny Young de la Sota:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/815960.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Sunny Young de la Sota:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/815960.
After addressing review feedback, remember to publish your drafts!

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