go-hamt-ipld
go-hamt-ipld copied to clipboard
feat!: use generics instead of cbg.Deferred
Experimenting with generics to do away with the deferred value decoding step.
The generic must conform to [T HamtValue[T]] where:
type HamtValue[T any] interface {
Equal(T) bool
MarshalCBOR(io.Writer) error
UnmarshalCBOR(io.Reader) error
}
*pointers are kind of awkward in this, tho I'm not sure I can do much better without heavier changes (e.g. there's situations where you want to passnilto indicate deletion)- The
Equalis a little annoying, but necessary to know whether we're mutating in certain situations FindRawis gone, doesn't make sense anymore I think.Findhas a current use-case where you passnilas the decoder and that means "I just want to know if it's there"; for certain typesTit'll be more expensive to decode the full node withTelements than it was to do thecbg.Deferredcbor token skip job. Maybe.- Needs some benchmarking in cases like the lotus actor state migration where I'm suspecting this might be of benefit.
- Maybe this could be
/v4but we still retain the/v3variant for some cases.
Experimentation with this going on over at https://github.com/filecoin-project/go-state-types/pull/298 against a >3M entry HAMT.
Rebased on #121, which has the restored cbor-gen code in it, so this now depends on https://github.com/whyrusleeping/cbor-gen/pull/103 for cbor-gen generics support.
Bailing on this for now, as per https://github.com/whyrusleeping/cbor-gen/pull/103#issuecomment-2398852941