-
Notifications
You must be signed in to change notification settings - Fork 148
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
Avoid unnecessary copies during config generation #6184
Conversation
This pull request does not have a backport label. Could you fix it @swiatekm? 🙏
|
|
3e175a0
to
969aac9
Compare
# Conflicts: # internal/pkg/agent/transpiler/ast.go
969aac9
to
f0bf34d
Compare
Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane) |
Quality Gate passedIssues Measures |
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.
Code changes look good to me, but I don't have much context here. It would be better for someone else to look at it as well.
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.
Nice improvement! Looks good.
if !ok { | ||
continue | ||
} | ||
hadStreams := false | ||
if streams := getStreams(dict); streams != nil { | ||
hadStreams = true | ||
} | ||
// Apply creates a new Node with a deep copy of all the values |
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.
Thanks for the comment here, helps with understanding that Apply is going to return a copy.
* Fix a bug in AST dictionary shallow cloning * Avoid unnecessary deepcopy during config generation * Don't unnecessarily copy AST when rendering inputs # Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 398f322)
* Fix a bug in AST dictionary shallow cloning * Avoid unnecessary deepcopy during config generation * Don't unnecessarily copy AST when rendering inputs # Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 398f322) # Conflicts: # internal/pkg/agent/transpiler/ast.go
* Fix a bug in AST dictionary shallow cloning * Avoid unnecessary deepcopy during config generation * Don't unnecessarily copy AST when rendering inputs # Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 398f322) # Conflicts: # internal/pkg/agent/transpiler/ast.go # internal/pkg/agent/transpiler/ast_test.go
* Fix a bug in AST dictionary shallow cloning * Avoid unnecessary deepcopy during config generation * Don't unnecessarily copy AST when rendering inputs # Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 398f322) # Conflicts: # internal/pkg/agent/transpiler/ast.go
* Fix a bug in AST dictionary shallow cloning * Avoid unnecessary deepcopy during config generation * Don't unnecessarily copy AST when rendering inputs # Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 398f322) Co-authored-by: Mikołaj Świątek <mail@mikolajswiatek.com>
* Fix a bug in AST dictionary shallow cloning * Avoid unnecessary deepcopy during config generation * Don't unnecessarily copy AST when rendering inputs # Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 398f322) # Conflicts: # internal/pkg/agent/transpiler/ast.go Co-authored-by: Mikołaj Świątek <mail@mikolajswiatek.com>
* Fix a bug in AST dictionary shallow cloning * Avoid unnecessary deepcopy during config generation * Don't unnecessarily copy AST when rendering inputs # Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 398f322) # Conflicts: # internal/pkg/agent/transpiler/ast.go # internal/pkg/agent/transpiler/ast_test.go # Conflicts: # internal/pkg/agent/transpiler/ast.go # internal/pkg/agent/transpiler/ast_test.go
* Fix a bug in AST dictionary shallow cloning * Avoid unnecessary deepcopy during config generation * Don't unnecessarily copy AST when rendering inputs # Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 398f322) # Conflicts: # internal/pkg/agent/transpiler/ast.go # internal/pkg/agent/transpiler/ast_test.go # Conflicts: # internal/pkg/agent/transpiler/ast.go # internal/pkg/agent/transpiler/ast_test.go
* Fix a bug in AST dictionary shallow cloning * Avoid unnecessary deepcopy during config generation * Don't unnecessarily copy AST when rendering inputs # Conflicts: # internal/pkg/agent/transpiler/ast.go (cherry picked from commit 398f322) # Conflicts: # internal/pkg/agent/transpiler/ast.go # internal/pkg/agent/transpiler/ast_test.go # Conflicts: # internal/pkg/agent/transpiler/ast.go # internal/pkg/agent/transpiler/ast_test.go Co-authored-by: Mikołaj Świątek <mail@mikolajswiatek.com>
What does this PR do?
Remove some unnecessary copies when generating component configuration.
The first copy avoided is done because we want to replace the
inputs
key with the rendered inputs. A shallow copy is sufficient for this. I did find and fix a bug in Dict shallow copies while at it.The rest of the copies have to do with applying vars to each AST node. We currently make a copy of each Node we do this for, but that's not necessary, as
Apply
creates a new Node with all the data recursively copied anyway. I've added a test to verify thatApply
actually works this way.Benchstat result vs
main
, using the benchmark from #6180:Why is it important?
More performance is good! More broadly, this is an attempt to incrementally improve the problem from #5991.
Checklist
./changelog/fragments
using the changelog toolRelated issues