Skip to content

Share the same Animated.Value amongst transitions that happen in the same commit#326

Merged
necolas merged 1 commit into
mainfrom
native/batch-similar-transitions
Jul 2, 2025
Merged

Share the same Animated.Value amongst transitions that happen in the same commit#326
necolas merged 1 commit into
mainfrom
native/batch-similar-transitions

Conversation

@martinbooth

Copy link
Copy Markdown
Contributor

Right now, updating state which affects transitioning properties accross multiple components results in each component creating its own Animated.Value and starting the animation in an effect.

This results in animations that are not in sync as they should be.

In this PR, transitions with the same delay, duration, timing function share the same Animated.Value as long as they're part of the same commit.

useLayoutEffect is used to either create the Animated.Value or find an existing suitable one to use.

Since all layout effects run before effects, we can assume that by the time any component's effect runs, all Animated.Values have been created or shared.

One of the component's effects will then kick off the animation and empty the shared animation config map so that future commits don't reuse any of the Animated.Values that were created. The other component's effects will be no-ops.

Finally, reference counting is used to ensure only the last component that unmounts would stop the animation if it was still running since now they are shared it would be disruptive to stop the animation unless the component was the last one relying on it

…same commit

Right now, updating state which affects transitioning properties accross
multiple components results in each component creating its own
Animated.Value and starting the animation in an effect.

This results in animations that are not in sync as they should be.

In this PR, transitions with the same delay, duration, timing function share
the same Animated.Value as long as they're part of the same commit.

useLayoutEffect is used to either create the Animated.Value or find an
existing suitable one to use.

Since all layout effects run before effects, we can assume that by the
time any component's effect runs, all Animated.Values have been created
or shared.

One of the component's effects will then kick off the animation and
empty the shared animation config map so that future commits don't
reuse any of the Animated.Values that were created. The other
component's effects will be no-ops.

Finally, reference counting is used to ensure only the last component
that unmounts would stop the animation if it was still running since
now they are shared it would be disruptive to stop the animation
unless the component was the last one relying on it
@github-actions

github-actions Bot commented Jul 2, 2025

Copy link
Copy Markdown

workflow: benchmarks/size

Comparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.

Results Base Patch Ratio
react-strict-dom/dist/dom/index.js
· compressed 2,513 2,513 1.00
· minified 8,695 8,695 1.00
react-strict-dom/dist/dom/runtime.js
· compressed 855 855 1.00
· minified 2,435 2,435 1.00
react-strict-dom/dist/native/index.js
· compressed 16,243 16,372 1.01 +
· minified 60,801 61,245 1.01 +

@github-actions

github-actions Bot commented Jul 2, 2025

Copy link
Copy Markdown

workflow: benchmarks/perf (native)

Comparison of performance test results, measured in operations per second. Larger is better.

Results Base Patch Ratio
css.create
· small 1,139,622 1,141,513 1.00 +
· small with units 407,192 421,523 1.04 +
· small with variables 648,206 656,008 1.01 +
· several small 310,173 317,082 1.02 +
· large 205,304 203,110 0.99 -
· large with polyfills 142,007 141,401 1.00 -
· complex 96,868 98,124 1.01 +
· unsupported 214,433 215,549 1.01 +
css.createTheme
· simple theme 223,048 226,657 1.02 +
· polyfill theme 213,354 212,613 1.00 -
css.props
· small 242,433 244,944 1.01 +
· small with units 191,212 191,087 1.00 -
· small with variables 106,126 106,369 1.00 +
· small with variables of units 74,015 74,973 1.01 +
· large 103,970 104,496 1.01 +
· large with polyfills 36,921 37,102 1.00 +
· complex 23,405 23,048 0.98 -
· unsupported 146,180 145,417 0.99 -
· simple merge 162,779 161,982 1.00 -
· wide merge 17,701 17,572 0.99 -
· deep merge 17,385 17,195 0.99 -
· themed merge 31,385 31,241 1.00 -

@necolas necolas merged commit 82a2ba2 into main Jul 2, 2025
8 checks passed
@necolas necolas deleted the native/batch-similar-transitions branch July 2, 2025 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants