Repository navigation
Size cuts for fetched components, with the repaint rule of #4139 - #4140
Conversation
|
This comment no longer applies. The failing Jest test came with #4139, and #4139 is out of this pull request since head 942d272. Generated by Claude Code |
70bfcc4 to
942d272
Compare
|
CircleCI This is not from this pull request. The test plays a 100 ms timeline backwards for 50 ms in real time. When one frame is longer than the rest of the timeline, the timeline finishes before So the failure is a slow frame on the CI machine, and behind it is a fault in Generated by Claude Code |
942d272 to
b772a5b
Compare
85b3736 to
941a26f
Compare
Reorder.Board looks up an element's drag controls in a map that was declared in the file of the class that makes them. A bundler keeps a module whole, so the class, PanSession and the projection geometry they use were in the first chunk of every page with Reorder. The map now has its own file. First load with Reorder: 42.96 kB to 38.49 kB gzip. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
A component that fetches the layout feature rendered all of MeasureLayout from its first render, so the code that drives a projection node sat in the first chunk. It now renders a shell with no logic of its own: each lifecycle method runs the method of the same name that arrives with the feature. Components that bundle their features are unchanged. Also fixes an exit that never finished. An async component with layout whose feature had not arrived, or with only drag, told AnimatePresence it could be removed before AnimatePresence had noted it as exiting, so the call was lost and the element stayed in the DOM. motion.div first load 34.08 -> 33.64 kB gzip. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
An exit animation only runs for a component that something keeps mounted after React would remove it. Components that fetch their features no longer bundle the exit feature: PresenceChild loads it for every motion component when it first renders. The PresenceContext that apps import loads it too, for a component that provides the context in place of AnimatePresence. Components that bundle their features, and the LazyMotion feature bundles, still include it. The feature now registers with its presence once the component has an animation state, so a component with the exit feature and no animation feature doesn't hold up its presence. The layout feature holds the MeasureLayout class and not its prototype. Reading the prototype as the module loaded stopped a bundler dropping the feature from a flattened bundle that doesn't use it. motion.div first load 33.64 -> 33.45 kB gzip. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
The branch combines the async features beta with four open performance changes, each of which set its own budgets. Also measure the whole React API through a namespace import: with a fetched chunk that imports from the first load, Rollup emitted `export *` as a second file that repeats every export, which added 2.3 kB that no app pays. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
A bundler that can't fetch code later puts the layout and drag code that motion/react fetches into its one file. esbuild also wraps every module that code shares with the rest of the file in a lazy initialiser, for any import from motion/react. motion/react-sync has the same exports, with motion components that bundle their features, so there's nothing to fetch or wrap. In an esbuild bundle without splitting, motion.div is 50.96 kB gzip (55.09 from motion/react), and m with LazyMotion and domAnimation is 34.04 kB (36.33). The entry name is provisional. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
A component starts animations and hands out no controls for them, so the code to pause, seek, change the speed of and attach a timeline to an animation doesn't need to be in a bundle with only components. supportPlayback() adds those controls to the shared animation classes. It's called by the code that gives an animation to its caller: animate(), animateValue(), animateSingleValue(), layout animations, timelines, and the animateTarget() and animateMotionValue() exports. The transform group's retiming of a running WAAPI animation moves with them. An inspector behind __MOTION_INSPECT__ controls the animations of components too. It gets the controls on development builds. motion.div first load: 33.45 kB to 32.57 kB gzip. animate(): +0.07 kB. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
Brings the repaint rule of #4139 onto the size commits. Up to 100 repainting elements on a touch device, and 2,000 on a computer, every transform stays on the compositor. Past that, transforms run on the main thread, and return to the compositor while other scripts block it. Replaces the rule that moved the transforms of six or more repainting elements to the main thread on every device. Sizes, gzip: motion.div first load 32.36 kB (31.68 kB with the old rule), animate 27.30 kB. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
On a CI machine busy with other suites, frames ran long after the test stopped its block, and the late probe timer read as other scripts. The transforms then stayed on the compositor past the 120 frames the test waits. The timer is held from the moment the block ends, as it is for the tests that never block. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
The speed tests compared a WAAPI animation with the animation that drives it in two reads of the clock. A stall between the reads counts twice at double speed, and CI had one of 25ms. Both are now read at one moment. The layer count test took the number of compositor layers before it started. Animations that earlier tests left running each held a layer until they finished, and some finished during the test. Each test's animations are now stopped before the next. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
Two tests of values in their delay read the value after a few frames and expect the delay of 0.5 seconds to still be running. On CircleCI the five frames of the first test took 529 ms, so the animation had started and the value was 29, not 0. A stall of 450 ms in the test gives the same failure here. The delay is now 10 seconds, and each test stops its animation once it has read the value. Test only. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
Three faults of the rule, found in review: A transform on a native scroll timeline was held on the main thread like any other while too many elements repainted. To hold it, it's made to follow its timeline from JS, and it can't go back. Only the compositor moves it with the scroll, so it's now never held. A `transform` animated directly that was held before its timeline was attached joins the timeline on the compositor, and one that follows a timeline from JS is no longer started again on a clock when the hold ends. A held `transform` at a speed of 0 returned to the compositor at its start. It's running, so it was given a start time, and at a rate of 0 that leaves it at 0. It's now set to where it's held. A transform that ended while it was held stayed in the set of held transforms, with its element, until the page stopped repainting. It's now forgotten when its animation finishes or stops. This is 62 bytes gzip on `animate`, so its bundlesize limit goes from 27.4 to 27.45 kB, and the Remix limit from 53.45 to 53.5 kB. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
Features are shared by every component on the page. The components that fetch layout code used to load their MeasureLayout for all of them, so an `m` component with `layout` took part once the code had arrived. Since the shell replaced it, the fetched code brought a projection node for an `m` component and nothing to drive it from React: no snapshot before a layout change, no layout group, no promotion. The shell is now loaded for every component, as MeasureLayout was. The exit feature also checks that a presence context has `register` before it calls it, as it did before it moved. Both found in review. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
From the second pass of the review. A component now keeps the MeasureLayout it first renders. Features are shared by every component on the page, and since the last commit the components that fetch layout code load the shell for all of them, where `LazyMotion` with `domMax` and the components that bundle their features load the bundled one. In an app with both, a mounted `m` or bundled component was given the other on a later render. That mounts it again, and a mount takes no snapshot, so that layout change wasn't animated. A transform group that was held before it joined a scroll timeline is forgotten when it joins, so the end of the hold doesn't build its animation again. A held `transform` is forgotten when its whole animation is stopped, not only when it is stopped alone. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
Main now holds #4125 and #4136, which add about 0.29 kB to a motion component and 0.11 kB to animate. The bundlesize limits for animate and Remix go to 27.55 kB and 53.65 kB for the same reason. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
845ee7c to
a13b523
Compare
Requested by Matt · project thread
Size cuts for
motioncomponents that fetch their layout and drag code.motion.divfrommotion/reacthas a first load of 32.74 kB gzip, down from 33.49 kB on main. That figure includes the repaint rule of #4139, which adds about 0.96 kB with the fixes from review.What the diff holds
The commits listed under "Changes", rebased on main at 783bbf1 on 4 December. Main now holds #4141, #4125 and #4136. Commit c68ea7e is the diff of #4139, and #4139 is closed in favour of this. #4105 is not in this pull request.
The repaint rule, measured
On main, the transforms of six or more elements that also animate a style on the main thread move to the main thread, on every device. Commit c68ea7e replaces that with the rule of #4139:
pointer: coarse), and 2,000 on a computer, every transform stays on the compositor.Results, in fps. Elements animate a transform and a style that repaints. Median of six shuffled rounds, no trace. They are from the head before the rebase of 4 December. A run of the rebased head is queued.
Sizes
Gzip kB from
node dev/inc/size-scenarios.mjs. The 14.x column is main before #4141. The main column is 783bbf1. The first load is the entry chunk and the chunks it imports statically, built with Rollup and terser.motion.div, first loadmotion.div, all chunksmotion.div+AnimatePresence, first loadReorder, first loadm+LazyMotion+domAnimationm+LazyMotion+domMaxanimatemotion.div, esbuild one file,motion/reactmotion.div, esbuild one file,motion/react-sync(new)Changes
Reorder's first load (0d5abbc). A map of drag controls shared a file with the drag controls class.Reorderread the map, so the class and the pan gesture came with it. The map has its own file.MeasureLayoutfrom its first render. It now renders a shell with no logic, and each lifecycle method runs the method that arrives with the layout feature.AnimatePresence(4a6fb21). An exit only runs underAnimatePresence.PresenceChildloads the exit feature, and so does the publicPresenceContextfor custom presence components. Bundled components and theLazyMotionbundles still include it.motion/react-sync(f1136be). The same exports asmotion/react, with components that bundle their features and fetch nothing. It is for builds that write one file. There, esbuild wraps each module that the fetched code shares with the rest of the file in a lazy initialiser, which costs about 4 kB. The name is provisional.supportPlayback()adds pause, seek, speed and timeline attach to the shared animation classes. The code that gives an animation to its caller calls it:animate(),animateValue(),animateSingleValue(), layout animations, timelines, and theanimateTarget()andanimateMotionValue()exports. The code that retimes a running WAAPI transform animation moved with it.motion.divfirst load against the six-element rule of main, about +0.96 kB against no rule, and +0.84 kB onanimate. Most of it is the check for a blocked main thread (about 0.42 kB).layoutbefore the layout code arrived was otherwise set up for layout when the code came.What changes for users
AnimatePresencealone is 3.80 kB (was 3.03 kB), because it carries the exit feature. Withmotion.divthe pair is smaller.__MOTION_INSPECT__can pause and seek the animations of components on development builds only. On a production build with only components it still gets every record, but those animations have nopause(),timeorspeed.AnimatePresencenever removed a fetchingmotion.divwithlayoutwhose layout code had not arrived, or one with onlydrag.Tests
In a cloud container, on this head (a13b523), after the rebase:
node dev/inc/size-scenarios.mjs --checkandbundlesize: pass.test), Playwright (test-html), Cypress on React 18 (test-react) and on React 19 (test-react-19), andmeasure. Its run on this head is the check to read.Size limits this pull request raises, and why:
animatebundlesize limit, 26.95 to 27.55 kB: the repaint rule is in every bundle that animates a transform with WAAPI.AnimatePresencesize budget, 3,150 to 3,950 bytes: it now carries the exit feature, whichmotion.divno longer does.CircleCI found failures on the way:
delay-sleep.test.ts, expected a delay of 0.5 seconds to still run after five frames. On CircleCI those frames took 529 ms. The delay is now 10 seconds (eab26e2, test only). This pull request does not change the code under that test.Not run: WebKit, Firefox and the Next.js tests. The device results under "The repaint rule, measured" are from the head before the rebase. Main has gained #4125 and #4136 since, so a run of this head is queued.
Review
Two independent reviews at high effort, one of
packages/motion-domand one of the rest, on eab26e2. Each then reviewed the fixes. Neither found a blocker. They found these faults, each fixed with a test that failed first:transformanimated directly are fixed with it (3c547d1).transformat a speed of 0 returned to the compositor at its start, not where it was held (3c547d1).transformwhose whole animation was stopped, and a transform that was held before it joined a scroll timeline was built one extra time when the hold ended (8e2c3ec).mcomponent withlayout, beside amotioncomponent that had fetched the layout code, got a projection node and nothing to drive it. On main it took part in layout animations. The layout shell is now loaded for every component, asMeasureLayoutwas (556348b).MeasureLayoutcomponents: the shell, and the full one fromdomMaxor a bundled component. A mounted component could change from one to the other, which remounted it and lost one layout animation. A component now keeps theMeasureLayoutof its first render (8e2c3ec).registeron a presence context without the check it had before it moved (556348b).Left as they are:
motion/react-synchas no explicitmexport for editor auto-import, asmotion/reacthas. The entry's name is not final.transformanimated directly that finished while it was held, and is then played again, stays on the main thread until it finishes.New tests: the first load has no projection-driving code, no exit feature and no playback code.
Reorderhas no drag modules. Each route that hands out an animation gives it controls, a component animation has none, and an inspector gets them. A transform group runs and finishes without playback. The layout shell drives a node that arrives late. A one-file build frommotion/react-synchas no lazy wrappers. The rule has the tests of #4139: the limits for touch and computer, the hold and the return, the blocked-thread check, and a directly animatedtransform.https://claude.ai/code/session_016xzo3aG8ZEbuWJW9bSLjET
Generated by Claude Code