Skip to content

Conversation

florianl
Copy link
Contributor

Description

When profiling some environments excessive calls to bytes.NewBuffer() and consequently additional GC workload was noticed. Use sync.Pool to reduce this overhead.

Link to tracking issue

Fixes #

Testing

Documentation

When profiling some environments excessive calls to bytes.NewBuffer() and consequently additional GC workload was noticed. Use sync.Pool to reduce this overhead.

Signed-off-by: Florian Lehner <[email protected]>
@florianl florianl requested a review from a team as a code owner September 26, 2025 09:07
@florianl florianl requested a review from jmacd September 26, 2025 09:07
Copy link

codecov bot commented Sep 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.63%. Comparing base (d00f059) to head (e53af78).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13909      +/-   ##
==========================================
- Coverage   91.65%   91.63%   -0.03%     
==========================================
  Files         652      652              
  Lines       42516    42523       +7     
==========================================
- Hits        38970    38965       -5     
- Misses       2736     2745       +9     
- Partials      810      813       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dmathieu
Copy link
Member

Could you share either benchmarks showing the improvement, or profiles before and after this change?

Signed-off-by: Florian Lehner <[email protected]>
@florianl
Copy link
Contributor Author

@dmathieu here are some numbers:

$ go test -bench=BenchmarkCompressRoundTripper -run=^$ -benchtime=8s
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/collector/config/confighttp
cpu: 12th Gen Intel(R) Core(TM) i7-12700H
BenchmarkCompressRoundTripper/Small_1KB_gzip_WithPool-20                  557988             26724 ns/op           28703 B/op        112 allocs/op
BenchmarkCompressRoundTripper/Small_1KB_gzip_NoPool-20                    570410             27245 ns/op           30017 B/op        115 allocs/op
BenchmarkCompressRoundTripper/Small_1KB_zstd_WithPool-20                  725426             21008 ns/op           18391 B/op        107 allocs/op
BenchmarkCompressRoundTripper/Small_1KB_zstd_NoPool-20                    763928             12327 ns/op           19925 B/op        111 allocs/op
BenchmarkCompressRoundTripper/Small_1KB_snappy_WithPool-20                281094             33449 ns/op           26842 B/op        112 allocs/op
BenchmarkCompressRoundTripper/Small_1KB_snappy_NoPool-20                  295188             35492 ns/op           27938 B/op        114 allocs/op
BenchmarkCompressRoundTripper/Medium_10KB_gzip_WithPool-20                438165             25951 ns/op           26833 B/op        113 allocs/op
BenchmarkCompressRoundTripper/Medium_10KB_gzip_NoPool-20                  405530             26554 ns/op           28015 B/op        117 allocs/op
BenchmarkCompressRoundTripper/Medium_10KB_zstd_WithPool-20                860119             21738 ns/op           20865 B/op        108 allocs/op
BenchmarkCompressRoundTripper/Medium_10KB_zstd_NoPool-20                  639778             22276 ns/op           21169 B/op        110 allocs/op
BenchmarkCompressRoundTripper/Medium_10KB_snappy_WithPool-20              261571             36828 ns/op           43490 B/op        113 allocs/op
BenchmarkCompressRoundTripper/Medium_10KB_snappy_NoPool-20                252706             38589 ns/op           44842 B/op        115 allocs/op
BenchmarkCompressRoundTripper/Large_100KB_gzip_WithPool-20                195235             46352 ns/op           16755 B/op        107 allocs/op
BenchmarkCompressRoundTripper/Large_100KB_gzip_NoPool-20                  186924             45780 ns/op           18505 B/op        112 allocs/op
BenchmarkCompressRoundTripper/Large_100KB_zstd_WithPool-20                596923             23384 ns/op           21277 B/op        111 allocs/op
BenchmarkCompressRoundTripper/Large_100KB_zstd_NoPool-20                  616399             23776 ns/op           23305 B/op        115 allocs/op
BenchmarkCompressRoundTripper/Large_100KB_snappy_WithPool-20              162502             55986 ns/op          202809 B/op        122 allocs/op
BenchmarkCompressRoundTripper/Large_100KB_snappy_NoPool-20                163826             50143 ns/op          198925 B/op        123 allocs/op
BenchmarkCompressRoundTripper/XLarge_1MB_gzip_WithPool-20                  32559            260401 ns/op            8576 B/op         87 allocs/op
BenchmarkCompressRoundTripper/XLarge_1MB_gzip_NoPool-20                    35058            263069 ns/op           26055 B/op         96 allocs/op
BenchmarkCompressRoundTripper/XLarge_1MB_zstd_WithPool-20                 273133             36299 ns/op           18345 B/op        112 allocs/op
BenchmarkCompressRoundTripper/XLarge_1MB_zstd_NoPool-20                   270033             36723 ns/op           18704 B/op        116 allocs/op
BenchmarkCompressRoundTripper/XLarge_1MB_snappy_WithPool-20                59028            154116 ns/op         1493545 B/op        123 allocs/op
BenchmarkCompressRoundTripper/XLarge_1MB_snappy_NoPool-20                  62806            152046 ns/op         1497548 B/op        124 allocs/op
PASS
ok      go.opentelemetry.io/collector/config/confighttp 316.170s

Feel free to reproduce the results with https://gist.github.com/florianl/22b50787ce38f0d637df17ed7875be42.

The benchmark is limited as they show only a limited number of http requests. When applying this change with more http requests and for a longer time, the benefits will be increase.

@atoulme
Copy link
Contributor

atoulme commented Oct 10, 2025

sorry @florianl would you please offer the benchmark results before/after on your computer so we can see the diff, using a tool like benchstat?

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.

5 participants