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: improve bitswap message merging #522

Merged
merged 3 commits into from
Apr 30, 2024

Conversation

achingbrain
Copy link
Member

When we send messages repeatedly to the same peer we spend most of our time base64 encoding data to dedupe messages.

This can happen when sending data to Kubo since it only sends us max 32x wants in one message, so for a large DAG we can receive many messages in quick succession.

Instead, encode the keys for blocks/wants/presences in base64 at message creation time, then when we need to merge messages it's a simple string comparison instead.

We need strings for comparison because JavaScript's Map type uses === to compare key values, if there was a Comparator-style interface we'd be able to use Uint8Arrays for keys, but there isn't, so we can't.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

When we send messages repeatedly to the same peer we spend most of
our time `base64` encoding data to dedupe messages.

This can happen when sending data to Kubo since it only sends us
max 32x wants in one message, so for a large DAG we can receive
many messages in quick succession.

Instead, encode the keys for blocks/wants/presences in base64 at
message creation time, then when we need to merge messages it's a
simple string comparison instead.

We need strings for comparison because JavaScript's `Map` type uses
`===` to compare key values, if there was a `Comparator`-style
interface we'd be able to use `Uint8Array`s for keys, but there
isn't, so we can't.
@achingbrain achingbrain requested a review from a team as a code owner April 27, 2024 12:27
@achingbrain achingbrain mentioned this pull request Apr 27, 2024
3 tasks
Copy link
Member

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

lgtm, two comments

@achingbrain achingbrain merged commit 7419dfc into main Apr 30, 2024
18 checks passed
@achingbrain achingbrain deleted the fix/improve-bitswap-message-merging branch April 30, 2024 06:35
@achingbrain achingbrain mentioned this pull request Apr 30, 2024
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