Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise our sum representation #113

Closed
doug-q opened this issue Sep 24, 2024 · 1 comment
Closed

Optimise our sum representation #113

doug-q opened this issue Sep 24, 2024 · 1 comment

Comments

@doug-q
Copy link
Collaborator

doug-q commented Sep 24, 2024

Currently we represent a sum as a struct with a u32 tag field and a field for each variant. Each variant field of the sum struct is a struct with a field per variant field. For example, a bool is {u32, {}, {}}, a int + float is {u32, {i64}, {f64}}. The tag field is elided for sums of a single variant. This is all implemented in sum.rs and the rest of the codebase SHOULD be agnostic as to the representation.

There are three avenues of optimisation:

  • Elide empty structs, elide the struct wrapper of single-field-variants, elide the outer sum struct when all variants are empty
  • Use the minimum-possible width for the tag field. in particular, for bool this is i1. and together with the previous optimisation, this makes the representation of bool i1.
  • We store all of the possible variants, with the unused ones poison. Instead, store a byte array of the length of the longest variant
@hugrbot
Copy link
Collaborator

hugrbot commented Nov 25, 2024

Migrated to hugr repo

@hugrbot hugrbot closed this as completed Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants