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

fix(bitswap): memory leak on BlockPresenceManager #636

Merged
merged 4 commits into from
Jul 26, 2024

Conversation

gammazero
Copy link
Contributor

Limit BlockPresenceManager map growth be doing the following:

  • Use nil map when BlockPresenceManager CID map is empty.
  • Delete peer map when from CID map when peer map is empty.
  • Remove peers from BlockPresenceManager when peers are pruned from session.

This allows GC to free memory when maps in BlockPresenceManager become empty.

Additional improvement: Do not look for lists of keys or peers in empty maps; return early instead.

Fix for issue #574

Limit BlockPresenceManager map growth be doing the following:

- Use nil map when BlockPresenceManager CID map is empty.
- Delete peer map when from CID map when peer map is empty.
- Remove peers from BlockPresenceManager when peers are pruned from session.

This allows GC to free memory when maps in BlockPresenceManager become empty.

Additional improvement: Do not look for lists of keys or peers in empty maps; return early instead.

Fix for issue #574
@gammazero gammazero requested a review from a team as a code owner July 8, 2024 22:47
Copy link

codecov bot commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 88.46154% with 3 lines in your changes missing coverage. Please review.

Project coverage is 59.90%. Comparing base (2816b71) to head (ad3c7c3).

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #636      +/-   ##
==========================================
+ Coverage   59.82%   59.90%   +0.07%     
==========================================
  Files         238      238              
  Lines       29976    29999      +23     
==========================================
+ Hits        17933    17970      +37     
+ Misses      10424    10415       -9     
+ Partials     1619     1614       -5     
Files Coverage Δ
...tswap/client/internal/session/sessionwantsender.go 96.70% <100.00%> (+0.47%) ⬆️
...ernal/blockpresencemanager/blockpresencemanager.go 96.70% <88.00%> (-3.30%) ⬇️

... and 13 files with indirect coverage changes

@lidel lidel changed the title Fix memory leak on BlockPresenceManager fix(bitswap): memory leak on BlockPresenceManager Jul 25, 2024
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

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

Optimizations lgtm, even if not fully solving #574, they make sense on their own.
Let's land this and ship together with #629.

@lidel lidel merged commit 08c1787 into main Jul 26, 2024
15 checks passed
@lidel lidel deleted the fix/block-presence-manager-mem-leak branch July 26, 2024 14:36
@lidel lidel mentioned this pull request Jul 26, 2024
4 tasks
wenyue pushed a commit to wenyue/boxo that referenced this pull request Oct 17, 2024
* Fix memory leak on BlockPresenceManager

Limit BlockPresenceManager map growth be doing the following:

- Use nil map when BlockPresenceManager CID map is empty.
- Delete peer map when from CID map when peer map is empty.
- Remove peers from BlockPresenceManager when peers are pruned from session.

This allows GC to free memory when maps in BlockPresenceManager become empty.

Additional improvement: Do not look for lists of keys or peers in empty maps; return early instead.

Fix for issue ipfs#574
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