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
Compute style changes before update #2776
Merged
Merged
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
3 tasks
3 tasks
tomekzaw
requested changes
Dec 29, 2021
tomekzaw
reviewed
Jan 5, 2022
tomekzaw
approved these changes
Jan 10, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
@piaskowyk Do you plan to release a new version with this patch included? Thanks! |
aeddi
pushed a commit
to aeddi/react-native-reanimated
that referenced
this pull request
Mar 22, 2022
## Description When I was doing performance optimizations, I removed function `styleDiff`, this function computes differences between old style and new style and returns only differences. In effect, we updated only changed style properties. When I removed the call of styleDiff (because was expensive) there was possible to call `layout()` too many times, even if someone doesn't change the layout property (layout is also expensive) but there was another problem because we need an update synchronous and asynchronous updates in the same `updateProps` call. So we decided to restore `styleDiff` but with faster implementation. We get rid of comparison by `JSON.stringify()`, the shall computation should be enough in this way. ## Benchmark <details> <summary>code</summary> ```js const objA = { a: 1, b: 2, c: {}, d: [], e: { a: 1 }, f: [1, 2, 3], g: [{a: 1}, {a: 2}, {a: 2}], h: 'abc', i: 'abc1', a1: 1, a2: 1, a3: 1, a4: 1, } const objB = { a: 1, b: 22, c: {}, d: [], e: { a: 11 }, f: [11, 22, 33], g: [{a: 11}, {a: 2}, {a: 2}], h: 'abc', i: 'abc2', } const iteration = 99999; for(let i = 0; i < 100; i++) { let a = performance.now(); } const t1_start = performance.now(); for(let i = 0; i < iteration; i++) { styleDiff_old(objA, objB); } const t1_end = performance.now(); const t2_start = performance.now(); for(let i = 0; i < iteration; i++) { styleDiff(objA, objB); } const t2_end = performance.now(); console.log( 'old', Math.round(t1_end - t1_start), 'ms', '|', 'new', Math.round(t2_end - t2_start), 'ms' ) ``` </details> Results: ``` old 919 ms | new 282 ms old 870 ms | new 283 ms old 901 ms | new 273 ms old 878 ms | new 306 ms old 868 ms | new 274 ms old 860 ms | new 266 ms old 907 ms | new 309 ms old 912 ms | new 334 ms old 922 ms | new 291 ms old 867 ms | new 261 ms old 880 ms | new 261 ms ``` In addition, this ```js state.last = Object.assign({}, oldValues, newValues); ``` fixes software-mansion#2752
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.
Description
When I was doing performance optimizations, I removed function
styleDiff
, this function computes differences between old style and new style and returns only differences. In effect, we updated only changed style properties. When I removed the call of styleDiff (because was expensive) there was possible to calllayout()
too many times, even if someone doesn't change the layout property (layout is also expensive) but there was another problem because we need an update synchronous and asynchronous updates in the sameupdateProps
call. So we decided to restorestyleDiff
but with faster implementation. We get rid of comparison byJSON.stringify()
, the shallow comparation should be enough in this way.Benchmark
code
Results:
In addition, this
fixes #2752