Reduce redundant layout calculations
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 827
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 40
Description
### What is the problem or limitation you are having?
Previous discussion:
* https://github.com/beeware/toga/pull/1794#issuecomment-1453096289
* https://github.com/beeware/toga/issues/2937#issuecomment-2449761045
Except for WinForms, none of the native platforms make any UI changes visible until the next main loop iteration, so we're doing a lot of redundant work. And even on WinForms, excessive updates will make the UI look unstable, and probably reduce performance.
This is particularly an issue with layout – if you insert N items into the layout, or you have N labels and you change the font or text on all of them, then we'll perform N layout passes, which will cost O(N ** 2) time.
### Describe the solution you'd like
Delay layout updates until the end of the current main loop iteration.
This may also affect non-layout style properties if they're assigned multiple times within a single main loop iteration, where only the final value really matters. But that's likely to be less of a performance issue, so it might not be worth the effort.
Contributor guide
Research direction
Start by reading the prior discussion in PR #1794 and issue #2937, since no implementation files or tests are named here. Trace how layout updates are scheduled across the native platforms, then verify that multiple changes in one main-loop iteration produce one effective layout pass without making WinForms updates unstable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- desktop, performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100