Add NewDigest, NewDigest64, NewDigest128#29
Merged
klauspost merged 1 commit intominio:masterfrom Oct 30, 2025
Merged
Conversation
klauspost
reviewed
Oct 30, 2025
b7066a0 to
3f5853d
Compare
New, New128, New64NewDigest, NewDigest64, NewDigest128
The `New`, `New64` and `New128` functions return a `hash.Hash` interface
from the standard library, but this prevents Go's heap escape analysis from
being able to determine whether or not the arguments to the `Sum` functions
should escape to the heap or not, therefore they _always_ escape.
For example, when trying to avoid the heap with a stack array allocation:
```
hh, _ := highwayhash.New64(...)
var hb [highwayhash.Size64]byte
if !bytes.Equal(hh.Sum(hb[:0]), ...) { ... }
```
... the `hash.Hash` type for `hh` guarantees that `hb` will always escape
whereas a concrete return type allows the heap escape analysis to run
correctly and avoid the heap escape.
Signed-off-by: Neil Twigg <git@neilalexander.dev>
3f5853d to
a40bc7c
Compare
Contributor
Author
|
Linter should be fixed now. |
Contributor
Author
|
Thanks for the fast review, any chance you'd be willing to tag as v1.0.4 please? |
neilalexander
added a commit
to nats-io/nats-server
that referenced
this pull request
Nov 10, 2025
This avoids heap escapes, see minio/highwayhash#29. Signed-off-by: Neil Twigg <neil@nats.io>
neilalexander
added a commit
to nats-io/nats-server
that referenced
this pull request
Nov 10, 2025
This avoids heap escapes, see minio/highwayhash#29. Signed-off-by: Neil Twigg <neil@nats.io>
neilalexander
added a commit
to nats-io/nats-server
that referenced
this pull request
Nov 10, 2025
This avoids heap escapes, see minio/highwayhash#29. Signed-off-by: Neil Twigg <neil@nats.io>
neilalexander
added a commit
to nats-io/nats-server
that referenced
this pull request
Nov 10, 2025
This avoids heap escapes, see minio/highwayhash#29. Signed-off-by: Neil Twigg <neil@nats.io>
delaneyj
pushed a commit
to delaneyj/nats-server
that referenced
this pull request
Nov 13, 2025
This avoids heap escapes, see minio/highwayhash#29. Signed-off-by: Neil Twigg <neil@nats.io>
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.
The
New,New64andNew128functions return ahash.Hashinterface from the standard library, but this prevents Go's heap escape analysis from being able to determine whether or not the arguments to theSumfunctions should escape to the heap or not, therefore they always escape.For example, when trying to avoid the heap with a stack array allocation:
... the
hash.Hashtype forhhguarantees thathbwill always escape whereas a concrete return type allows the heap escape analysis to run correctly and avoid the heap escape.Signed-off-by: Neil Twigg git@neilalexander.dev