-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Even faster flexbox #122
Merged
Merged
Even faster flexbox #122
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Method invocations are not entirely free on Android. Change the generated Java code to use the same array-based approach used in JS and C to compute dimensions, positions, etc instead of relying too heavily on method invovations. As a bonus, the Java transpiler becomes a lot simpler because the code is more analogous to the C counterpart. In my local benchmarks this change gives us a major performance boost on Android (between 15% and 30%) depending on the device and the runtime (Dalvik|Art).
Store immutable values from the node being laid out to avoid unnecessary method invocations during layout calculation. This gives us a 3%-5% performance boost in my benchmarks on Android.
There's no need to set the trailing position on left-to-right layouts as the nodes will already have what we need (x, y, width, and height). This means we still have an extra cost for reversed layout directions but they are not as common as LTR ones.
There's no need to go through all children before starting the main line loop as we'll visit all children in the former loop anyway. This diff merges the pre-fill loop into the main line one to avoid an extraneous traversal on the node's children.
There's no need to go through all absolute children at the end of the layout calculation if the node at hand doesn't have any. This also ensures only absolutely positioned children are traversed in the final loop.
We were traversing all children to only perform calculations/changes to flexible children in order to avoid new allocations during layout. This diff ensures we only visit flexible children during layout calculations if any are present. We accomplish this by keeping a private linked list of flexible children.
No need to check for RELATIVE position when position type is ABSOLUTE and dimension is set.
Remaining space and between space only need to be updated when justifyContent is not FLEX_START.
The correct check is on the layout state, no the style.
Change the initial line loop to opportunistically position children in the in container with simple stacking params i.e. vertical/horizontal stacking on non-flexible STRETCH/FLEX_START aligned. This allows us to skip the main and cross axis loops (Loop C and D, respectively) partially and even completely in many common scenarios. In my benchamrks, this gives us about ~15% performance win in many setups.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This branch has a series of changes on top #121 that makes css-layout an extra 15% faster in my benchmarks on Android.
Besides a couple of micro-optimizations, this branch implements an optimization for simple stacked layouts (vertical/horizontal layouts with non-flexible children aligned with STRETCH/FLEX_START) which are very common in most UIs. This change allows us to skip Loop C and D (main and cross axis, respectively) partially and even completely in many cases.