Skip to content

Optimize runtime sizes of some structures #816

@sethdusek

Description

@sethdusek

ergovalidation keeps a large LRU cache of boxes to speed up validation, but this requires a large amount of memory. Reduce the size of ErgoBox. Some ideas how to do this:

  • Use Box<[T]> instead of Vec<[T]> where possible. ErgoBox should be immutable anyways so growable collections are not needed
  • Reduce ErgoTree size:
    • ErgoTreeHeader can be stored in 1 byte instead of 3 (don't unpack is_constant_segregation and has_size flags)
    • Use Box<[Constant]> for constants
    • Remove lazy has_deserialize. Using OnceCell requires 4 bytes of space, isn't supported on no_std and doesn't save that much time anyway (one tree pass to check if tree contains deserialize nodes). Change has_deserialize to Option, if ErgoTree was deserialized
    • Reduce Expr Size:
      • Change Spanned to use u32 indexes instead of usize
      • Expr size will be atleast the size of the largest node, which is currently MethodCall. Change MethodCall.args to Box<[Expr]>, optimize SMethodDesc similarly. In the future MethodCall could be changed to only contain information that can't be inferred so it doesn't contain the entire Method description
  • Optimize Constant/SType size

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions