Switched list iteration flow for GameObject rendering and updates#277
Switched list iteration flow for GameObject rendering and updates#277huggyex64 wants to merge 2 commits into
Conversation
Introduce a full event subsystem (Prowl.Runtime.Events) with EventManager, Event<T>, delegate containers, diagnostics, attributes, and helpers; add an EventDomain source generator (Prowl.Runtime.Generators) and EquatableArray. Update core types to use scene event flow: SceneEvents, WindowEvents, GameEvents and generated accessors; change OnRenderCollect signatures to use SceneEvents.OnRenderCollectArgs and propagate renderable/light lists. Wire Game/Window/Scene/GameObject/MonoBehaviour to subscribe and dispatch events, execution order calculation, batching, and subscription management. Update project/solution files to include the generator project.
Replace DEBUG-guarded event diagnostics with EVENT_DEBUG to allow selective compilation of event diagnostics. Add allowMultiple parameter to EventAccessor.Subscribe overloads and propagate it through EventManager so multiple identical subscriptions can be allowed. Introduce Scene.MarkExecutionOrdersDirty and defer recalculation of execution/priorities to once-per-frame (SubscribeObjectsToEvents/RecalculateExecutionOrders) with batching around recalculation. Adjust GameObject/MonoBehaviour to mark scenes dirty when hierarchy/component changes and subscribe scene-level handlers with allowMultiple where needed. Misc: minor reorders to ensure consistent update/subscribe behavior.
|
First off, thanks for taking the time to put this together Ive gone through the PR, and I think the performance improvements are significant That said, Im not convinced we need the full event framework to achieve it If the main issue were trying to solve is avoiding full GameObject traversal every frame, I think the solution may be able to stay much simpler For example, we could potentially maintain static collections of active components that participate in Update, FixedUpdate, rendering, etc, with components registering and unregistering themselves as they become active or inactive, based on whether those virtual methods have been overridden which could be cached per type That would give us many of the same benefits:
The event system certainly works (in fact I think its quite clever could be a nice standalone Prowl library) but I also feel it pushes Prowl away from the KISS philosophy the project is built around Would you be interested in exploring a simpler implementation focused specifically on update/render registration? Either way, I really appreciate the work that went into this PR |
|
My suggestion for this PR is: make it do the LEAST amount possible needed for GameObject components to subscribe to events, and thats it. This PR looks like an entire Event system package. As an example of what Wulferis means by "KISS" (Keep it simple stupid) the EditorAssetDatabase is at most 5 scripts in total. |
Instead of iterating over all the active objects to gather the renderables, call updates, call fixedupdates, etc..., this implementation has the objects subscribed to an event manager that reduces the call overhead by a lot.
Among other notable improvements, there are:
Following are two small benchmarks ran with ~1800 gameobjects with 7 monobehaviour each, for a total of ~12600 monobehaviours. each with an Update that rotates the transform.


before:
after: