Skip to content

Conversation

bernardobelchior
Copy link
Member

@bernardobelchior bernardobelchior commented Sep 17, 2025

Related to #12960 (comment).

Original StackBlitz
StackBlitz pointing to this PR.

Fixes the performance issue with JS animations. In the reproductions above, I'm seeing a reduction for Last Contentful Paint from 8.0s to 0.5s, resulting in a 16x improvement.

The issue was caused by calling timerFlush() which flushes all timers. This meant that whenever resume() or finish() were being called, we were calling all timer callbacks.

For 3600 bars, this means that every time a new bar N was added, we were calling N-1 callbacks. That's why if could added a console.log in timerCallback you were seeing more than 200k logs.

I removed timerFlush and had to update the tests but this seems more in line with what would be expected. I've done some manual tests and animations seems to work properly, but I'll do some more extensive testing.

Toggling skipAnimation on and off still seems to be working as well as updating the bar prop while animating:

Screen.Recording.2025-09-17.at.14.59.51.mov

@mui-bot
Copy link

mui-bot commented Sep 17, 2025

Deploy preview: https://deploy-preview-19606--material-ui-x.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts ▼-10B(0.00%) ▼-7B(-0.01%)
@mui/x-charts-pro ▼-10B(0.00%) ▼-4B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against d32b156

@bernardobelchior bernardobelchior added type: bug It doesn't behave as expected. scope: charts Changes related to the charts. labels Sep 17, 2025
Copy link

codspeed-hq bot commented Sep 17, 2025

CodSpeed Performance Report

Merging #19606 will not alter performance

Comparing bernardobelchior:fix-animation-perf-issue (d32b156) with master (66a5676)

Summary

✅ 12 untouched

@bernardobelchior bernardobelchior marked this pull request as ready for review September 17, 2025 14:00
import { Transition } from './Transition';

// Wait for the next animation frame
const waitNextFrame = () =>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't use vitest fake timers because they were failing on CI when running in browser mode.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd, does the logic required animation frame? It could not work if it just using timers instead.


await waitNextFrame();
expect(callCount()).to.be.equal(reactMajor > 18 ? 3 : 2);
expect(callCount()).to.be.equal(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks more stable 👍

Copy link
Member

@JCQuintas JCQuintas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch

@bernardobelchior bernardobelchior merged commit 112c08f into mui:master Sep 18, 2025
22 checks passed
@bernardobelchior bernardobelchior deleted the fix-animation-perf-issue branch September 18, 2025 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance scope: charts Changes related to the charts. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants