matter-ecs / matter

A modern ECS library for Roblox
https://matter-ecs.github.io/matter/
MIT License
64 stars 11 forks source link

Add more debug profiling #24

Open jackTabsCode opened 7 months ago

jackTabsCode commented 7 months ago

There is a lot of unprofiled or incorrectly profiled code in the library (see World:query). Profiling all parts of Matter will allow us to narrow down performance issues in Matter's internals.

Ukendio commented 7 months ago

I agree with adding more diagnostics, but not for the same reason. We want to implement this to allow the users know how much the iteration is taking of their systems' times.

We may want to be careful with debug profiler as they add non trivial overhead which is problematic for iterators that run multiple times and I don't think O2 removes them.

If we just want to give people the query speeds in their systems, all we have to do is make our debugger call a query for each entity archetype, or cached queries, I am not sure. For this the debugger needs to hook the world which I think it already does at some point?

If we want to use it internally between ourselves to track performance issues, I suggest we make a test build of sorts that enables profiling. We shouldn't impose this on the users.

Side note: if you are just curious about the performance issues in the internals then most of the overhead from the query is clearly the expanding, where 60% of that function goes to unpack. And the rest goes to nextItem, maybe something to do with it doing extra gymnastics to prevent iterator invalidation.

jackTabsCode commented 1 month ago

I think that, especially with the world rewrite in progress, we should make sure code paths are accurately and extensively profiled. What if we had an API to enable debug profiling? That solves the overhead problem.