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

Reduce allocation in discovery by ~30% #2350

Merged
merged 2 commits into from
Jan 8, 2025

Conversation

thampiotr
Copy link
Contributor

@thampiotr thampiotr commented Jan 8, 2025

PR Description

This is a low hanging fruit fix to reduce allocation in discovery components by around 30%. More work may still be required in the future.

Which issue(s) this PR fixes

Notes to the Reviewer

thampiotr@MacWork ~/w/alloy (thampiotr/reduce-disco-allocation)> go test -count 5 -bench=Benchmark_ToAlloyTargets -benchmem ./internal/component/discovery/ | tee after.txt; benchstat before.txt after.txt
goos: darwin
goarch: arm64
pkg: github.com/grafana/alloy/internal/component/discovery
cpu: Apple M2
Benchmark_ToAlloyTargets-8   	     150	   7549967 ns/op	12768249 B/op	   40433 allocs/op
Benchmark_ToAlloyTargets-8   	     169	   7257841 ns/op	12767441 B/op	   40430 allocs/op
Benchmark_ToAlloyTargets-8   	     171	   7026276 ns/op	12767394 B/op	   40430 allocs/op
Benchmark_ToAlloyTargets-8   	     170	   7060700 ns/op	12767377 B/op	   40430 allocs/op
Benchmark_ToAlloyTargets-8   	     170	   7034392 ns/op	12767427 B/op	   40430 allocs/op
PASS
ok  	github.com/grafana/alloy/internal/component/discovery	15.349s
goos: darwin
goarch: arm64
pkg: github.com/grafana/alloy/internal/component/discovery
cpu: Apple M2
                  │  before.txt  │              after.txt              │
                  │    sec/op    │    sec/op     vs base               │
_ToAlloyTargets-8   9.679m ± ∞ ¹   7.061m ± ∞ ¹  -27.05% (p=0.008 n=5)
¹ need >= 6 samples for confidence interval at level 0.95

                  │  before.txt   │              after.txt               │
                  │     B/op      │     B/op       vs base               │
_ToAlloyTargets-8   18.24Mi ± ∞ ¹   12.18Mi ± ∞ ¹  -33.24% (p=0.008 n=5)
¹ need >= 6 samples for confidence interval at level 0.95

                  │  before.txt  │              after.txt              │
                  │  allocs/op   │  allocs/op    vs base               │
_ToAlloyTargets-8   60.45k ± ∞ ¹   40.43k ± ∞ ¹  -33.12% (p=0.008 n=5)

And the before:

cat before.txt
goos: darwin
goarch: arm64
pkg: github.com/grafana/alloy/internal/component/discovery
cpu: Apple M2
Benchmark_ToAlloyTargets-8   	     123	  10320177 ns/op	19125568 B/op	   60453 allocs/op
Benchmark_ToAlloyTargets-8   	     122	   9597422 ns/op	19124639 B/op	   60450 allocs/op
Benchmark_ToAlloyTargets-8   	     123	   9639463 ns/op	19125584 B/op	   60454 allocs/op
Benchmark_ToAlloyTargets-8   	     123	   9684174 ns/op	19124906 B/op	   60451 allocs/op
Benchmark_ToAlloyTargets-8   	     120	   9678773 ns/op	19125101 B/op	   60452 allocs/op
PASS
ok  	github.com/grafana/alloy/internal/component/discovery	16.564s

PR Checklist

  • CHANGELOG.md updated
  • Documentation added
  • Tests updated
  • Config converters updated

@thampiotr thampiotr changed the title Reduce allocation in discovery by 30% Reduce allocation in discovery by ~30% Jan 8, 2025
Copy link
Contributor

@wildum wildum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch

@thampiotr thampiotr marked this pull request as ready for review January 8, 2025 13:40
@thampiotr thampiotr requested a review from a team as a code owner January 8, 2025 13:40
@thampiotr thampiotr merged commit 2b78534 into main Jan 8, 2025
18 checks passed
@thampiotr thampiotr deleted the thampiotr/reduce-disco-allocation branch January 8, 2025 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants