-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[charts] Fix performance issue with JS animations #19606
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
[charts] Fix performance issue with JS animations #19606
Conversation
Deploy preview: https://deploy-preview-19606--material-ui-x.netlify.app/ Bundle size report
|
CodSpeed Performance ReportMerging #19606 will not alter performanceComparing Summary
|
580b951
to
d32b156
Compare
import { Transition } from './Transition'; | ||
|
||
// Wait for the next animation frame | ||
const waitNextFrame = () => |
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.
Couldn't use vitest fake timers because they were failing on CI when running in browser mode.
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.
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); |
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.
Looks more stable 👍
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.
nice catch
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 wheneverresume()
orfinish()
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
intimerCallback
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