Skip to content

reverseproxy: use xxhash.Sum64String in load balancer hashing#7846

Open
jvoisin wants to merge 1 commit into
caddyserver:masterfrom
jvoisin:haspeed
Open

reverseproxy: use xxhash.Sum64String in load balancer hashing#7846
jvoisin wants to merge 1 commit into
caddyserver:masterfrom
jvoisin:haspeed

Conversation

@jvoisin

@jvoisin jvoisin commented Jun 29, 2026

Copy link
Copy Markdown

The hash helper used by hostByHashing (ip_hash, header, cookie, and query hashing policies) created a new xxhash.Digest and converted the input to []byte on every call, i.e. per upstream per request. Replace it with the stateless xxhash.Sum64String, which hashes the string in a single pass.

Adds a BenchmarkHostByHashing benchmark, as per policy, even though it's a tad silly. The only change is sec/op (484.2n -> 407.3n (-15.87%)) from skipping the digest struct initialization and Write bookkeeping. Allocations are unchanged, since escape analysis already stack-allocated the Digest and the []byte conversion.

Assistance Disclosure

"No AI was used."

The hash helper used by hostByHashing (ip_hash, header, cookie, and query
hashing policies) created a new xxhash.Digest and converted the input to
[]byte on every call, i.e. per upstream per request. Replace it with the
stateless xxhash.Sum64String, which hashes the string in a single pass.

Adds a BenchmarkHostByHashing benchmark, as per policy, even though it's a tad
silly. The only change is sec/op (484.2n -> 407.3n  (-15.87%)) from skipping
the digest struct initialization and Write bookkeeping. Allocations are
unchanged, since escape analysis already stack-allocated the Digest and the
[]byte conversion.
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.

1 participant