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

Use deque instead of slice for queues #742

Merged
merged 3 commits into from
Dec 6, 2024
Merged

Conversation

gammazero
Copy link
Contributor

@gammazero gammazero commented Dec 5, 2024

Implementing a queue by appending to a slice will makes more GC work as the end of slice's memory is reached. Instead use a deque that maintains a circular buffer that reuses memory from removed items.

Fixed a case where a new timer was created during each iteration of a loop, instead of reusing a timer.

Implementing a queue by appending to a slice will make more GC work as then end of slice's memory is reached. Instead use a deque that maintains a circular buffer that reuses memory from removed items.
Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 75.92593% with 13 lines in your changes missing coverage. Please review.

Project coverage is 60.40%. Comparing base (ef25808) to head (16f33ac).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
bitswap/client/internal/session/cidqueue.go 14.28% 11 Missing and 1 partial ⚠️
bitswap/testnet/virtual.go 87.50% 1 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #742      +/-   ##
==========================================
+ Coverage   60.38%   60.40%   +0.01%     
==========================================
  Files         245      245              
  Lines       31069    31063       -6     
==========================================
+ Hits        18762    18763       +1     
+ Misses      10635    10628       -7     
  Partials     1672     1672              
Files with missing lines Coverage Δ
...client/internal/messagequeue/donthavetimeoutmgr.go 95.19% <100.00%> (ø)
bitswap/network/connecteventmanager.go 86.25% <100.00%> (-2.47%) ⬇️
bitswap/network/ipfs_impl.go 79.48% <100.00%> (-1.86%) ⬇️
ipld/merkledag/merkledag.go 76.58% <100.00%> (+0.22%) ⬆️
ipld/merkledag/traverse/traverse.go 66.66% <100.00%> (-0.61%) ⬇️
ipld/unixfs/hamt/hamt.go 76.62% <100.00%> (-0.04%) ⬇️
bitswap/testnet/virtual.go 68.42% <87.50%> (ø)
bitswap/client/internal/session/cidqueue.go 51.28% <14.28%> (-8.72%) ⬇️

... and 7 files with indirect coverage changes

@gammazero gammazero marked this pull request as ready for review December 6, 2024 05:11
@gammazero gammazero requested a review from a team as a code owner December 6, 2024 05:11
@gammazero gammazero force-pushed the use-deque-for-queue branch from 07bb8ab to fe91a64 Compare December 6, 2024 20:21
@gammazero gammazero merged commit 9709204 into main Dec 6, 2024
15 checks passed
@gammazero gammazero deleted the use-deque-for-queue branch December 6, 2024 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant