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

Use C# arrays as pluggable storage for managed types #21

Open
BeanCheeseBurrito opened this issue Mar 6, 2024 · 0 comments
Open

Use C# arrays as pluggable storage for managed types #21

BeanCheeseBurrito opened this issue Mar 6, 2024 · 0 comments

Comments

@BeanCheeseBurrito
Copy link
Owner

When pluggable storages are added to flecs, pinned C# arrays should be used as storage for managed types.

Performance - Special unboxing code is required per every iteration in the current design. Using plain C# arrays will remove this overhead and bring the performance of managed component iteration on par with native C# ECS frameworks/libraries.

Memory Allocations - This will greatly reduce memory consumption due to only needing a single GCHandle and Box<T> object to be allocated per column instead of per component.

Debugging - With the current setup, it is not possible to inspect the contents of a column for both managed and unmanaged types inside a debugger due to the GCHandle indirection and unboxing step required for managed objects. Switching to C# array storage will replace the Column<T> type with the Span<T> type and allow the contents of components to be displayed in the debugger.

Pointer APIs - Pointer-based APIs in Flecs.NET are currently restricted to unmanaged types only. This restriction can be removed entirely as using pinned C# arrays will allow us to retrieve pointers to managed component references. This is a prerequisite to being able to properly implement serialization and deserialization for managed types.

// Pointer-based iteration
Query.Iter((Iter it, Position* p, Velocity* v) => { });

// Span-based iteration
Query.Iter((Iter it, Span<Position> p, Span<Velocity> v) => { });

// Get raw pointers to managed objects.
Position* p = e.GetPtr<Position>();
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

1 participant