multiformats / rust-multiaddr

multiaddr implementation in rust
https://crates.io/crates/multiaddr
Other
86 stars 45 forks source link

Purpose of Arc in Multiaddr #90

Open dariusc93 opened 1 year ago

dariusc93 commented 1 year ago

i was searching for why Arc was used after my overnight test shown additional allocation tracing back to the Arc in Multiaddr (probably unrelated, though it did catch my eye). The previous commit that made the change did not mention the reason for using it, and looking over the code, removing the Arc should work just fine and without being a breaking change.

thomaseizinger commented 1 year ago

I believe the idea is that it is cheap to clone. The Multiaddr::push function for example uses clone-on-write to either reuse the current allocation if there are no other copies or make a new one on the fly.

imbrem commented 1 year ago

I've made pull request #89 to preserve the cheap clone while making the semantics clearer and improving (hopefully, still benchmarking) efficiency by using an EcoVec<u8>, downside is it adds a dependency on https://github.com/typst/ecow