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: cache string and tuple representations #275

Merged
merged 3 commits into from
Sep 29, 2022

Conversation

achingbrain
Copy link
Member

Converting multiaddrs to strings and tuples is expensive and done in many places so cache these representations when they are first requested.

Converting multiaddrs to strings and tuples is expensive and done
in many places so cache these representations when they are first
requested.
@achingbrain achingbrain changed the title fix: cache string and tuple represntations fix: cache string and tuple representations Sep 21, 2022
@achingbrain
Copy link
Member Author

achingbrain commented Sep 22, 2022

These operations are surprisingly expensive:

image

The above is js-ipfs idling with the DHT enabled. The percentage is total CPU time.

achingbrain added a commit to libp2p/js-libp2p that referenced this pull request Sep 22, 2022
It turns out because `Multiaddr.encapsulate` stringifies the `Multiaddr`
it's a [suprisingly expensive operation](multiformats/js-multiaddr#275 (comment))
so here we switch the order of our `Multiaddr` pipeline around so
we filter undialable addresses (e.g. unsupported transports etc) before
encapsulating the `PeerId` onto a `Multiaddr` we'd then just ignore.
mpetrunic pushed a commit to libp2p/js-libp2p that referenced this pull request Sep 23, 2022
It turns out because `Multiaddr.encapsulate` stringifies the `Multiaddr`
it's a [suprisingly expensive operation](multiformats/js-multiaddr#275 (comment))
so here we switch the order of our `Multiaddr` pipeline around so
we filter undialable addresses (e.g. unsupported transports etc) before
encapsulating the `PeerId` onto a `Multiaddr` we'd then just ignore.
@achingbrain achingbrain merged commit 9b18ff4 into master Sep 29, 2022
@achingbrain achingbrain deleted the fix/cache-string-and-tuples branch September 29, 2022 12:25
github-actions bot pushed a commit that referenced this pull request Sep 29, 2022
## [11.0.2](v11.0.1...v11.0.2) (2022-09-29)

### Bug Fixes

* cache string and tuple representations ([#275](#275)) ([9b18ff4](9b18ff4))
@github-actions
Copy link

🎉 This PR is included in version 11.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant