This deserves some discussion before implementation.
The largest contributor to our bundle size is codecs and hash algorithms. When unused these are completely unnecessary bundle bloat, and rarely are all of the codecs and hashes we bundle actually used. The get-codec library ships with only 4 codecs (raw, dag-json, dag-cbor, and dag-pb) and is already an unnacceptable bundle size for a dependency. Cutting down to just raw or maybe raw and dag-json should be an acceptable size.
But it’s worth discussing what the optimal API is for configuring which codecs and hash functions should be bundled. The Block API is in a weird place in the application stack, instances are created at a fairly low level and then passed on to higher level code, so it’s a bit hard to figure out where users would pass in these implementations.
We already have an API for configuring/adding codecs to the block interface but I’m not sure how I feel about it. It just exposes the get-codec interface.
Block.getCodec.setCodec(‘codec-name’, implementation)
There’s no equivalent API in multihashing-async so we’ll probably have to drop it and write our own.
Thoughts?
PS. When we removed async from encode() and decode() we also removed the ability to dynamically load a codec over the network. That may have been a mistake, but it’s not something I want to re-litigate until we have a better understanding of the performance tradeoffs. However, block.cid() is still async, and will remain so because browser hashing algorithms are async, and that means we could implement dynamic loading for hashing algorithms.