tim-harding / soa-rs

An SoA library for Rust
MIT License
113 stars 2 forks source link

Feature suggestion: Array of enum variants #4

Closed VorpalBlade closed 8 months ago

VorpalBlade commented 8 months ago

I know you are probably busy with the soundness issues right now, so this is going to to be low priority.

I recently ran into an issue where I had wildly varying sizes for different enum members. I could of course box one of them if it is rare, but I had a pretty even distribution in my case. Could we derive a "array of enum variants" similar to this that simply puts all instances of different enum types in different arrays internally, thus reducing memory usage and improving cache locality? I don't know what a good API would look like, some thought is required here.

tim-harding commented 8 months ago

Yes! I absolutely want to do this, although I plan on doing it as a separate crate. This is a good design I would like to emulate: https://alic.dev/blog/dense-enums