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

Packed/sparse representations #91

Open
Ralith opened this issue Oct 17, 2020 · 0 comments
Open

Packed/sparse representations #91

Ralith opened this issue Oct 17, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@Ralith
Copy link
Owner

Ralith commented Oct 17, 2020

It might be useful/fun to allow certain components to be stored per archetype in ways other than a flat array. For example, a bool component might be stored in a packed bitfield, and a bool component which is nearly always false might benefit from sparse encoding. This could be pursued with something like:

trait Container<T> { /* ... */ }

struct Array<T>(Box<[T]>);

impl<T> Container<T> for Array { /* ... */ }

trait Component<T: Container<Self> = Array<T>>: Send + Sync + Sized + 'static {}
impl<T: Send + Sync + 'static> Component<Array<T>> for T {}

This preserves the "It Just Works" behavior for typical cases, while allowing specialized implementations as needed. The proposed definition of Array would break up the currently monolithic Archetype allocations; in the event that this compromises performance, an allocator abstraction could be introduced to allow multiple containers to share a single memory region.

The most obviously useful nonstandard container, a bitfield, would require container-specific smart pointer types in place of references. This will be difficult to accomplish without GATs, so it's probably best to wait their arrival before developing this concept further.

@Ralith Ralith added the enhancement New feature or request label Oct 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant