wrap-cli icon indicating copy to clipboard operation
wrap-cli copied to clipboard

Optimize Wrapper ABI

Open dOrgJelli opened this issue 3 years ago • 1 comments

Currently, the WRAP ABI structure has a lot of redundant data. This is because the nested redundant data is useful when generating code, but is unneeded elsewhere.

We should optimize the ABI structure to ensure that it serializes to as small of a size as possible.

Example Optimization

Optimized:

{
  name: "uArrayArray",
  required: true,
  kind: 34,
  array: {
    type: "[[UInt]]",
    required: true,
    kind: 18,
    array: {
      type: "[UInt]",
      kind: 18,
      scalar: {
        type: "UInt",
        kind: 4
      }
    }
  }
}

Original:

{
  type: "[[UInt]]",
  name: "uArrayArray",
  required: true,
  kind: 34,
  array: {
    type: "[[UInt]]",
    name: "uArrayArray",
    required: true,
    kind: 18,
    array: {
      type: "[UInt]",
      name: "uArrayArray",
      kind: 18,
      scalar: {
        type: "UInt",
        name: "uArrayArray",
        kind: 4
      },
      item: {
        type: "UInt",
        name: "uArrayArray",
        kind: 4
      }
    },
    item: {
      type: "[UInt]",
      name: "uArrayArray",
      kind: 18,
      scalar: {
        type: "UInt",
        name: "uArrayArray",
        kind: 4
      },
      item: {
        type: "UInt",
        name: "uArrayArray",
        kind: 4
      }
    }
  }
}

NOTE: we can add back this redundant data using transformations, that way our codegen string templates do not need to be changed.

dOrgJelli avatar Aug 15 '22 05:08 dOrgJelli

I think this is really important! The wrap.info file can get really big right now.

Uniswap v3 example: wrap.info -> 171kb wrap.wasm -> 799kb

krisbitney avatar Aug 23 '22 16:08 krisbitney