bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Make subapps run in parallel with main app

Open PhaestusFox opened this issue 1 year ago • 1 comments

What problem does this solve or what need does it fill?

I was making a video about sub-apps as I thought they would be useful if someone wanted to brake a game up into differently controlled worlds (eg no hostile pathfinding systems in the sub-app and just swap the app and sub-app worlds when the player "moves" between them), but while I was doing some testing and reading the code I found that the sub-apps are run consecutively rather than in parallel, this undermines what I thought would be the biggest selling point of sub-app, they all have independent worlds and schedules so don't have to worry about conflicting systems with mutable access allowing for maximum concurrency. I know the render sub-app runs in parallel to the main app but I don't know enough about how it does this to make suggestions on how this could be replicated in other sub-apps. this would also pair well with #6700 allowing you to basically create a sup-app say a self-contained mini-dungeon like a scene, but unlike a scene, these two worlds don't have to worry about conflicting with each other since they don't share the same world and can therefore have there own self contained resources and states.

What solution would you like?

I would like to see sub-apps run their extract function consecutively and then all run updates in parallel rather than currently running one at a time (extract, extract, ext... parallel update) vs (extract, update, extract, update, ext, ext...)

What alternative(s) have you considered?

move sub-apps out of the App struct and into a resource inside the world, this also fixes #6700 since you could access the resource inside systems and change it. this may not be possible as I don't know why the sub-apps have a dedicated place in the main app, would make some sense if they run in parallel since then the app doesn't need world access to run them but schedulers found a way around this by removing them self from the world then running

Leaving it up to the community to make third-party plugins to achieve the same result, probably thou a resource containing worlds and schedulers and an exclusive system.

PhaestusFox avatar Jul 05 '23 02:07 PhaestusFox

This would be helpful. My sub app can become relatively intense as it is used for netcode physics corrections which involves rollback and it can become CPU intensive. To get parallel Worlds to calculate in Bevy you can also use Thread and ditch SubApp entirely with mpsc messages they can run in parallel and sync data together. However having two main Bevy threads as they're separated seems like a potential source of CPU inefficiencies.

starwolfy avatar Jan 25 '24 22:01 starwolfy