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 #1698

Open
hugrbot opened this issue Nov 25, 2024 · 0 comments
Open

Optimise our sum representation #1698

hugrbot opened this issue Nov 25, 2024 · 0 comments
Labels
llvm Pertains to LLVM emission

Comments

@hugrbot
Copy link
Collaborator

hugrbot commented Nov 25, 2024

Originally raised by @doug-q:

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 hugrbot added the llvm Pertains to LLVM emission label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm Pertains to LLVM emission
Projects
None yet
Development

No branches or pull requests

1 participant