-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use xxhash instead of sha256 for hashing AST nodes #6192
Conversation
Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane) |
This pull request is now in conflicts. Could you fix it? 🙏
|
69dde06
to
d8326e3
Compare
d8326e3
to
d7220b4
Compare
# Conflicts: # internal/pkg/agent/transpiler/ast.go
d7220b4
to
5b699bf
Compare
Quality Gate passedIssues Measures |
@@ -58,6 +59,9 @@ type Node interface { | |||
// Hash compute a sha256 hash of the current node and recursively call any children. | |||
Hash() []byte | |||
|
|||
// Hash64With recursively computes the given hash for the Node and its children | |||
Hash64With(h *xxhash.Digest) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just replace the usage of Hash()
? Why do you have both? Do we need both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need both. If there were a bunch of callers of Hash
, then I'd be in favor of keeping it and implementing it using Hash64With
, but there aren't, so we can get rid of it. I was planning to do so in a follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, removal in follow-up is good.
# Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 9c13110)
# Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 9c13110) # Conflicts: # internal/pkg/agent/transpiler/ast.go
# Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 9c13110) # Conflicts: # go.mod # internal/pkg/agent/transpiler/ast.go
# Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 9c13110) # Conflicts: # go.mod # internal/pkg/agent/transpiler/ast.go
# Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 9c13110) Co-authored-by: Mikołaj Świątek <[email protected]>
# Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 9c13110) # Conflicts: # go.mod # internal/pkg/agent/transpiler/ast.go # Conflicts: # internal/pkg/agent/transpiler/ast.go
# Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 9c13110) # Conflicts: # go.mod # internal/pkg/agent/transpiler/ast.go # Conflicts: # internal/pkg/agent/transpiler/ast.go
# Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 9c13110) # Conflicts: # go.mod # internal/pkg/agent/transpiler/ast.go # Conflicts: # internal/pkg/agent/transpiler/ast.go
# Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 9c13110) # Conflicts: # go.mod # internal/pkg/agent/transpiler/ast.go # Conflicts: # internal/pkg/agent/transpiler/ast.go Co-authored-by: Mikołaj Świątek <[email protected]>
# Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 9c13110) # Conflicts: # internal/pkg/agent/transpiler/ast.go
# Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 9c13110) # Conflicts: # internal/pkg/agent/transpiler/ast.go # Conflicts: # internal/pkg/agent/transpiler/ast.go
# Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 9c13110) # Conflicts: # internal/pkg/agent/transpiler/ast.go # Conflicts: # internal/pkg/agent/transpiler/ast.go
# Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 9c13110) # Conflicts: # internal/pkg/agent/transpiler/ast.go # Conflicts: # internal/pkg/agent/transpiler/ast.go
# Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 9c13110) # Conflicts: # internal/pkg/agent/transpiler/ast.go # Conflicts: # internal/pkg/agent/transpiler/ast.go Co-authored-by: Mikołaj Świątek <[email protected]>
) (elastic#6252)" This reverts commit 0b8bd08.
) (elastic#6252)" This reverts commit 0b8bd08.
What does this PR do?
We currently use sha256 for hashing AST nodes when generating configuration. This is used both for checking equality between AST instances and for avoiding recomputing inputs unnecessarily. This PR changes this to xxHash, which is much faster. It also changes the interface, letting the caller supply their own hasher instance, and avoiding needing to allocate one for each Node in the tree.
Of note is that I'm using the
xxhash.Digest
struct as an argument instead of the generichash.Hash64
interface from the standard library. The reason is that the former has an optimizedWriteString
method, which avoid needing to cast the string to a byte slice. I also don't expect to need to actually supply different hash implementations to this method.Note also that there's already fairly exhaustive tests for this, some unexpected behaviour included.
Why is it important?
It's a pretty significant performance improvement. See the benchstat results using the benchmark from #6180:
Checklist
./changelog/fragments
using the changelog toolRelated issues