cadence icon indicating copy to clipboard operation
cadence copied to clipboard

Encode complex types only once

Open robert-e-davidson3 opened this issue 2 years ago • 0 comments

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:

  1. 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.
  2. 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.

robert-e-davidson3 avatar Sep 16 '22 00:09 robert-e-davidson3