Performant approach/best practice for rendering dynamically changing amount of elements. #3218
Unanswered
LoserAntbear
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Greetings, fellow friends.
Trying to apply skia for game development here. I'm trying to marry skia and ECS currently. Sadly, pretty fast I've encountered an issue: when you try to process and render dynamically changing array of entities the app stutters, rendering the data from previous frame, rather than updated one.
Code structure:
ECS registry is an instance, which keeps entities and components.
Gameloop executes on every
useFrameCallback
, where systems are processing serialized arrays of entities.Since ECS registry is a global namespace constant I need to inject ECS registry into React ecosystem. To achieve this I've created ECSContext, which holds an array of currently existing entities and their components.
Thus entities for serialization are fetched from this ECSContext.
When I push an entity into an array the context updates it's value, triggering the react lifecycle updates. That's pretty straightforward and simple, I presume.
Alas, when I try to render the given items the app "stutters" on every
entities array
change (e.g. when the entity is being pushed, popped from the array). I reckon that this happens because the Canvas has to re-process it's tree on every update and this is a heavy operation, which leads to a de-sync between UI and RN threads.Minimal boilerplate code example for the case:
ECS Registry
:ECS Context
:App
:GameLoop
:MainScene
:I understand that this is pretty verbose, but I don't want to miss a thing.
I'm adding a new entity into the
entities
array every 300ms, which are hidden behind the screen (to avoid screen space pollution). This produces given stutters.Could you, probably point out the possible caveats and issues I'm not noticing? Since I've tried a lot of thing - from immutable states, to controlled render calls - it still produces stutters. Like on the video attached.
skia_stutters.mp4
Beta Was this translation helpful? Give feedback.
All reactions