Fix slow flexbox layout when auto sized #504
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
This PR is mostly for discussion of a better caching solution that should address #502.
This PR introduces a call frame cache that lives only for the duration of a given layout pass. It's implemented purely internally (in a thread local) to avoid breaking changes to the public APIs.
It has switches to conditionally engage the cache depending on if the flexbox layout algorithm is recursive. But I'm sure these "on" switches are just a rough approximation of where it should be determined to use this cache.
I originally developed this against the
0.3.11
sha (0bccf6c) (old, fast branch) and saw a 5 - 10x speedup for flex auto use cases. After rebasing ontomain
, I no longer see a considerable speedup (only about 10% speedup) and I'm sure the additional work of checking whether to cache and caching slows down other non-flex-auto paths. It appears thatcompute_node_layout
is now called with a more diverse range of values than before, causing the cache to miss and bloat over the course of a layout.It feels like there should be a way to performantly cache the results in a robust way. After testing, changes to styling like flex direction and margins have surprising impacts on performance and I think that caching should "just work" regardless of the current combination of style settings.
Context
Discuss any context that may be needed for reviewers to understand the changes you've made.
This may include related issues, previous discussion, or links to documentation or code.
Feedback wanted
I hope this PR inspires an implementation that works.