rust-multiaddr icon indicating copy to clipboard operation
rust-multiaddr copied to clipboard

Purpose of Arc in Multiaddr

Open dariusc93 opened this issue 2 years ago • 2 comments

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.

dariusc93 avatar Apr 27 '23 12:04 dariusc93

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.

thomaseizinger avatar Apr 27 '23 13:04 thomaseizinger

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

imbrem avatar Apr 28 '23 11:04 imbrem