DioxusLabs / blitz

High performance HTML and CSS renderer powered by WGPU
Apache License 2.0
2.13k stars 42 forks source link

ECS design #150

Open matthunz opened 4 weeks ago

matthunz commented 4 weeks ago

I've noticed quite a few comments mentioning a future refactor to an ECS based design, which I think would be great to bring back! The ECS paradigm seems to fit us well here by making it easy to parallelize our state management and render pipeline.

I think bevy_ecs would be the perfect fit for us, especially since we may be able to integrate with their Accesskit, and Winit support (among other things).

Outline

This sounds like a major change so just to outline the steps I think we could take:

Finally we may be able to replace our rendering logic with systems, potentially simplifying the crates here and increasing performance. This I imagine could be a longer term goal, but one I think that would come with major benefits.

Sharing more with Bevy

nicoburns commented 4 weeks ago

I'm open to potentially switching to an ECS, but I'm a little wary of it:

I suspect it won't ever make sense to go down the full bevy_ui route. Blitz's DOM is considerably more capable at rendering HTML than bevy_ui, and bevy probably won't want to take on all the legacy code required to implement that. I think we should continue down a route of modular crates where it makes sense (winit, taffy, parley, cosmic-text, accesskit, wgpu, vello, etc - and maybe bevy_ecs), but not attempt to share glue code where we may well want to diverge on the implementation.

matthunz commented 4 weeks ago

Huh I think I see your points, but I have grown really fond of the Rust + ECS combo. I think it helps with maintainability quite a bit, even if a custom solution like stylo's would probably be ideal, hopefully we can still get close to that multi-threaded performance. I remember chatting about this for Masonry's design and yeah ECS doesn't pair too great with trees, but with systems only accessing what they need and Query::par_iter we can potentially run a lot of our current pipeline concurrently.

IIRC the last few versions of Blitz featured an ECS so I was hoping those comments were indicative we were doing the same here 👀

Also I guess I do agree it doesn't make sense to use parts of bevy_ui. Blitz DOM's capabilities now are something I hope we can preserve doing this change, and bevy_ui might be too hard to bend into shape. I do still think bindings like bevy_vello, bevy_winit, and bevy_a11y would fit well here for the lower level gaps.