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

Change the memory queue implementation to not pre-allocate capacity objects. #12070

Merged
merged 1 commit into from
Jan 11, 2025

Conversation

bogdandrutu
Copy link
Member

@bogdandrutu bogdandrutu commented Jan 10, 2025

Change the sized channel to use a "fifo" queue without pre-allocated capacity:

  • Allows us to soon allow different sizers like bytes, which otherwise would pre-allocate way too much memory. E.g. if configure with a limit of 1GB would pre-allocate 16GB for the buffered channel only.
  • Does not pre-allocate memory when not needed.

Before:

cpu: Apple M2 Max
BenchmarkOffer
BenchmarkOffer/requests_based
BenchmarkOffer/requests_based-12         	 5559658	       207.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkOffer/items_based
BenchmarkOffer/items_based-12            	 6025567	       209.4 ns/op	       0 B/op	       0 allocs/op

After:

cpu: Apple M2 Max
BenchmarkOffer
BenchmarkOffer/requests_based
BenchmarkOffer/requests_based-12         	 4904857	       224.3 ns/op	      48 B/op	       1 allocs/op
BenchmarkOffer/items_based
BenchmarkOffer/items_based-12            	 5470143	       229.9 ns/op	      48 B/op	       1 allocs/op

Overall there is a ~20ns performance downgrade but this is expected since no memory pre-allocation.

Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.68%. Comparing base (e6df9d8) to head (2144722).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12070      +/-   ##
==========================================
+ Coverage   91.66%   91.68%   +0.01%     
==========================================
  Files         455      455              
  Lines       24005    24039      +34     
==========================================
+ Hits        22005    22039      +34     
  Misses       1629     1629              
  Partials      371      371              

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

@bogdandrutu bogdandrutu changed the title [chore] Simplify sized channel by not using a channel, remove corner case Change the memory queue implementation to not pre-allocate capacity objects. Jan 10, 2025
@bogdandrutu bogdandrutu force-pushed the sized-queue branch 3 times, most recently from bb3faf0 to 466ce29 Compare January 10, 2025 22:36
@bogdandrutu bogdandrutu marked this pull request as ready for review January 10, 2025 22:37
@bogdandrutu bogdandrutu requested a review from a team as a code owner January 10, 2025 22:37
@bogdandrutu bogdandrutu requested a review from songy23 January 10, 2025 22:37
Copy link
Member

@dmitryax dmitryax left a comment

Choose a reason for hiding this comment

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

Nice!

@bogdandrutu bogdandrutu added this pull request to the merge queue Jan 11, 2025
Merged via the queue into open-telemetry:main with commit 7f4664e Jan 11, 2025
53 checks passed
@bogdandrutu bogdandrutu deleted the sized-queue branch January 11, 2025 03:37
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