Skip to content
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

[8.16](backport #6184) Avoid unnecessary copies during config generation #6247

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Dec 9, 2024

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 that Apply actually works this way.

Benchstat result vs main, using the benchmark from #6180:

goos: linux
goarch: amd64
pkg: github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator
cpu: 13th Gen Intel(R) Core(TM) i7-13700H
                                      │ bench_main.txt │          bench_noclone.txt          │
                                      │     sec/op     │   sec/op     vs base                │
Coordinator_generateComponentModel-20     37.99m ± 24%   32.36m ± 4%  -14.82% (p=0.000 n=10)

                                      │ bench_main.txt │          bench_noclone.txt           │
                                      │      B/op      │     B/op      vs base                │
Coordinator_generateComponentModel-20     34.22Mi ± 0%   25.38Mi ± 0%  -25.84% (p=0.000 n=10)

                                      │ bench_main.txt │          bench_noclone.txt          │
                                      │   allocs/op    │  allocs/op   vs base                │
Coordinator_generateComponentModel-20      810.7k ± 0%   580.4k ± 0%  -28.40% (p=0.000 n=10)

Why is it important?

More performance is good! More broadly, this is an attempt to incrementally improve the problem from #5991.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool

Related issues


This is an automatic backport of pull request #6184 done by [Mergify](https://mergify.com).

@mergify mergify bot requested a review from a team as a code owner December 9, 2024 16:09
@mergify mergify bot added backport conflicts There is a conflict in the backported pull request labels Dec 9, 2024
@mergify mergify bot requested review from pkoutsovasilis and swiatekm and removed request for a team December 9, 2024 16:09
Copy link
Contributor Author

mergify bot commented Dec 9, 2024

Cherry-pick of 398f322 has failed:

On branch mergify/bp/8.16/pr-6184
Your branch is up to date with 'origin/8.16'.

You are currently cherry-picking commit 398f3229b8.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   changelog/fragments/1733158776-avoid-copies-config-gen.yaml
	modified:   internal/pkg/agent/application/coordinator/coordinator.go
	modified:   internal/pkg/agent/transpiler/ast_test.go
	modified:   internal/pkg/agent/transpiler/utils.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   internal/pkg/agent/transpiler/ast.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@swiatekm swiatekm enabled auto-merge (squash) December 9, 2024 16:12
* 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
@swiatekm swiatekm force-pushed the mergify/bp/8.16/pr-6184 branch from 9f6d5ef to a6be95d Compare December 9, 2024 16:28
Copy link

Quality Gate failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 40%)

See analysis details on SonarQube

@swiatekm swiatekm removed the conflicts There is a conflict in the backported pull request label Dec 9, 2024
@swiatekm swiatekm merged commit 23c79fe into 8.16 Dec 9, 2024
14 of 15 checks passed
@swiatekm swiatekm deleted the mergify/bp/8.16/pr-6184 branch December 9, 2024 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant