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 #6058) Don't deepcopy AST when generating vars #6111

Merged
merged 1 commit into from
Nov 23, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Nov 21, 2024

What does this PR do?

We generate vars from mappings from both context providers and dynamic providers. Dynamic providers can produce multiple var entries - the Kubernetes provider will do so for each Pod, for example. When that happens, we currently make a deep copy of the context provider mapping, and add the dynamic provider mapping as a key.

As we don't modify the mappings, this deep copy can be replaced by a shallow copy. This PR introduces shallow copying to the AST and uses it when generating vars, leading to a major performance improvement.

Why is it important?

All these deep copies can be quite expensive when there's a lot of mappings from the dynamic provider. See the benchstat report below:

goos: linux
goarch: amd64
pkg: github.com/elastic/elastic-agent/internal/pkg/composable
cpu: 13th Gen Intel(R) Core(TM) i7-13700H
                       │ bench_main.txt │          bench_shallow.txt          │
                       │     sec/op     │   sec/op     vs base                │
GenerateVars100Pods-20    15247.8µ ± 4%   778.8µ ± 7%  -94.89% (p=0.000 n=10)

                       │ bench_main.txt │          bench_shallow.txt           │
                       │      B/op      │     B/op      vs base                │
GenerateVars100Pods-20   10273.4Ki ± 0%   779.1Ki ± 0%  -92.42% (p=0.000 n=10)

                       │ bench_main.txt │          bench_shallow.txt          │
                       │   allocs/op    │  allocs/op   vs base                │
GenerateVars100Pods-20     201.28k ± 0%   22.13k ± 0%  -89.00% (p=0.000 n=10)

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 #6058 done by [Mergify](https://mergify.com).

@mergify mergify bot requested a review from a team as a code owner November 21, 2024 11:19
@mergify mergify bot added backport conflicts There is a conflict in the backported pull request labels Nov 21, 2024
@mergify mergify bot requested review from andrzej-stencel and michel-laterman and removed request for a team November 21, 2024 11:19
Copy link
Contributor Author

mergify bot commented Nov 21, 2024

Cherry-pick of db6fbe2 has failed:

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

You are currently cherry-picking commit db6fbe2429.
  (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:
	modified:   internal/pkg/agent/transpiler/ast.go
	modified:   internal/pkg/agent/transpiler/ast_test.go
	modified:   internal/pkg/agent/transpiler/vars.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   internal/pkg/composable/controller.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

@pierrehilbert pierrehilbert requested review from swiatekm and removed request for andrzej-stencel and michel-laterman November 21, 2024 11:44
@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Nov 21, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

Copy link
Contributor Author

mergify bot commented Nov 21, 2024

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b mergify/bp/8.16/pr-6058 upstream/mergify/bp/8.16/pr-6058
git merge upstream/8.16
git push upstream mergify/bp/8.16/pr-6058

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 merged commit 72697af into 8.16 Nov 23, 2024
13 of 14 checks passed
@swiatekm swiatekm deleted the mergify/bp/8.16/pr-6058 branch November 23, 2024 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport conflicts There is a conflict in the backported pull request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants