Skip to content

Optimization: Shorter option binary representation via invalid value (e.g. -1 == None of option<resource>) #437

Open
@cpetig

Description

@cpetig

Today I realized that option<my-resource> or option<borrow<my-resource>> could have the same size and representation as the resource itself, because (at least in the current bindings) -1 is used as an invalid value for the resource index.

As I didn't find the invalid value nor the optimization documented in the canonical ABI, I wonder whether this would be a reasonable addition to the spec. Similarly string and vector could have defined invalid representations which could optimize the representation of an option.

See https://doc.rust-lang.org/std/option/index.html#representation for the documentation of the Null Pointer Optimization on Rust.

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