reactive-python / reactpy

It's React, but in Python
https://reactpy.dev
MIT License
7.89k stars 317 forks source link

Concurrent Renders #1165

Closed rmorshea closed 11 months ago

rmorshea commented 12 months ago

By submitting this pull request you agree that all contributions to this project are made under the MIT license.

Issues

Currently ReactPy renders components sequentially. This means that larger renders can block smaller updates from taking place which impacts responsiveness of the page. Sequential renders are also problematic for async effects since effects which are slow to start and stop can similarly impact the responsiveness of a page.

Solution

This change now allow renders to take place concurrently. To keep things simple, no effort is made to deduplicate renders. For example, if parent and child components are scheduled to render at the same time, both scheduled renders will take place even though a single render of the parent component would be sufficient to update the view.

Concurrent renders are achieved by "asyncifying" the internals of the Layout class. Additionally all scheduled renders immediately result in a "render task" being started. To avoid rendering the same component at the same time, we introduce a semaphore inside LifeCycleHooks that must be acquired before a component is rendered.

Note: this contains a subset of the changes originally created in https://github.com/reactive-python/reactpy/pull/1093

Checklist

rmorshea commented 11 months ago

I'll be able to finish this off over the weekend.

Archmonger commented 11 months ago

There's still a couple of comments on my original review that need discussion.