cadence
cadence copied to clipboard
Encode complex types only once
Right now, the complex types are encoded in-line with their values. If two values have the same type, the type is encoded twice.
The complex types should only be encoded once. There are two approaches; part of this ticket is to decide on an approach:
- Encode the types in a header. Each instance of the type will be replaced with a pointer to the type in the header. A pointer in this case is the byte offset in the header.
- Continue to encode types in-line. The first type will be encoded as is done today but subsequent types will be encoded as pointers to that in-lined type.
The first approach has the advantage of providing a header that can be partially or totally omitted if the client already knows the types. (It's only partial when encoding an abstract type because a concrete type is needed for decoding.)
The second approach is a little smaller and faster.
It may be desirable to support both approaches. This would be done by encoding that as a feature flag in the first byte of the encoding, where the codec type and version is indicated.