Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

feat: cache the materialized wantlist #530

Merged
merged 2 commits into from
Oct 26, 2021
Merged

Conversation

Stebalien
Copy link
Member

This can become a hot-spot.

wantlist/wantlist.go Outdated Show resolved Hide resolved
This can become a hot-spot.
// called frequently.

// Add each regular want-have / want-block to the message.
if msgSize+(len(peerEntries)*bsmsg.MaxEntrySize) > mq.maxMessageSize {
Copy link
Member Author

Choose a reason for hiding this comment

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

We're now eagerly sorting which could affect performance. However, I believe the real perf issue was that we were repeatedly sorting the same broadcast list over-and-over, which we're now doing at most once per change.

Copy link
Contributor

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

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

LGTM but I would love to see a test to make sure the cache-busting and sorting works as expected.

Also I assume there was a performance bottleneck observed in production that motivated this change. I suggest we observe performance in the same situation before merging to make sure this solves the problem.

This test explicitly calls entries to make sure the cache is
materialized.
@Stebalien
Copy link
Member Author

@dirkmc

Sorting test is

func TestSortEntries(t *testing.T) {
. I've added a test that should explicitly test clearing the cache on add/remove.

Copy link
Contributor

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@Stebalien Stebalien merged commit d48cbc1 into master Oct 26, 2021
@Stebalien Stebalien deleted the feat/cache-wantlist branch October 26, 2021 15:48
@aschmahmann aschmahmann mentioned this pull request Dec 1, 2021
80 tasks
Jorropo pushed a commit to Jorropo/go-libipfs that referenced this pull request Jan 26, 2023
feat: cache the materialized wantlist

This commit was moved from ipfs/go-bitswap@d48cbc1
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants