Skip to content

Research and optimize Data serialization code #13

Open
@szg251

Description

@szg251

Issue by: kozross
Original date: 2023-06-14 21:15:43 UTC
Originally opened as: mlabs-haskell/trustless-sidechain/issues/484
Original assignees: kozross
Status on 2023-06-20: open


Description

Follow-on from input-output-hk/trustless-sidechain#426. Currently, we're seeing significant size blowouts when comparing scripts measured as CompiledCode versus their serialized forms. This could be due to the 'bundling' of Data deserialization code: we frequently use autogenerated instances, which are suboptimal in some cases, many of which we encounter. For example, product types are always encoded as Constr, even though we end up carrying around a tag which we never need, but still have to store and match on. Furthermore, instead of re-using fromBuiltinData in UnsafeToData, the generated code duplicates this functionality, causing much more duplication than necessary.

This somewhat supercedes input-output-hk/trustless-sidechain#477 and encompasses some parts of input-output-hk/trustless-sidechain#480.

Goals

  • Test whether changing Data-related instances improves serialized script size
  • If it does, see how small a reduction we can obtain
  • Document this in a guide!

Tests

As these instances are now manually written, some additional tests should be written. These should verify the following all hold:

  • fromBuiltinData . toBuiltinData = Just
  • unsafeFromBuiltinData . toBuiltinData = id

It would also be good to include some tests that 'bad' encodings fail to deserialize, but these are type-specific and may not always be practical. QuickCheck is appropriate for such tests.

Measurements of just the Data-related methods would probably be good to have also.

Related issues/PRs

  • input-output-hk/trustless-sidechain#63
  • input-output-hk/trustless-sidechain#60
  • input-output-hk/trustless-sidechain#558

Metadata

Metadata

Assignees

No one assigned

    Labels

    optimizationImproving execution speed and costsresearchWe want to do this but don't know yet how

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions