multiformats / js-cid

CID implementation in JavaScript
MIT License
97 stars 39 forks source link

perf: cache buffer form of CID when created #74

Closed alanshaw closed 5 years ago

alanshaw commented 5 years ago

I quickly threw this together in response to https://github.com/ipfs/js-ipfs/issues/1788.

Right now, when attempting to get content not in the local repo, cid.buffer will be requested multiple times. See:

https://github.com/ipfs/js-ipfs-repo/blob/01a47375f5a07c5b9b3312c1674923a3c2854ae8/src/blockstore.js#L163-L171

cidToDsKey accesses cid.buffer and will be called twice in this one method (and possibly other times throughout the code base) so in this case it is worth the overhead of caching the buffer because recreating it is expensive.

resolves https://github.com/ipfs/js-ipfs/issues/1788

alanshaw commented 5 years ago

@vmx shall we merge?