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

aggregator: don't allocate memory if we don't have tags #297

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

iksaif
Copy link
Contributor

@iksaif iksaif commented Dec 15, 2023

Before:
BenchmarkGetContextNoTags-10 39929401 29.70 ns/op 16 B/op 1 allocs/op

After:
BenchmarkGetContextNoTags-10 419886585 2.902 ns/op 0 B/op 0 allocs/op

This might look not much, but this makes a lot of difference in term of allocation when a counter is called repeatedly inside a loop.

This also fixes the other benchmarks that I wanted to run to validate I didn't cause regression but where not able to run properly

We can see it in this profile (referencing line 182 explicitely):
Screenshot 2023-12-15 at 11 52 49

Referencing https://github.com/DataDog/datadog-go/blob/master/statsd/aggregator.go#L182 as the main cause of allocation

From a simple call to Count:
statsd.Count("rollout.done", 1, nil, 1.0)

Before:
BenchmarkGetContextNoTags-10    	39929401	        29.70 ns/op	      16 B/op	       1 allocs/op

After:
BenchmarkGetContextNoTags-10    	419886585	         2.902 ns/op	       0 B/op	       0 allocs/op

This might look not much, but this makes a lot of difference in term of allocation
when a counter is called repeatedly inside a loop.
@iksaif iksaif requested a review from a team as a code owner December 15, 2023 10:44
Copy link
Contributor

@remeh remeh left a comment

Choose a reason for hiding this comment

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

LGTM. Good catch.

@iksaif iksaif merged commit 515814d into master Dec 20, 2023
38 checks passed
@iksaif iksaif deleted the corentin.chary/performance-improvements branch December 20, 2023 08:42
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.

None yet

2 participants