rxjs icon indicating copy to clipboard operation
rxjs copied to clipboard

Performance issue with multiple concurrent uses of animationFrameScheduler

Open fdeslandes-wk opened this issue 3 years ago • 2 comments
trafficstars

Describe the bug

Since version 7.5.0, there is a huge performance loss with animationFrameScheduler when there are a lot of timers emitting concurrently using the scheduler. The problem can be painfully obvious on slower machines and was found in our application using Angular CDK virtual scroll.

There was no such performance issue in version 7.4.0. The problem have probably been created by this code change

The performance issue is big enough to prevent the migration of our application to RxJs 7.5 + as it makes some parts of it near unusable.

Expected behavior

Independant observables using the animationFrameScheduler should not have a big performance impact on each others.

Reproduction code

See the Stackblitz code.

See the result in the console using rxJs 7.5.0 vs using rxJs 7.4.0. The result is dependant on your computer's performance, but should be quite obvious regardless

Reproduction URL

https://stackblitz.com/edit/rxjs-afsbug?file=package.json,index.ts

Version

7.5.0

Environment

No response

Additional context

Works properly and is a lot more performant before 7.5.0

fdeslandes-wk avatar Jul 08 '22 18:07 fdeslandes-wk

Can confirm, we are downgrading to 7.4 after finding out that some parts of an application that relies on animationFrameScheduler is working only sometimes.

FDIM avatar Jul 26 '22 12:07 FDIM

It looks like the issue is something to do with the addition of looping through all existing actions to see if the id is already scheduled in recycleActionId. cc @cartant who was doing some work in there.

recycleActionId is called every time schedule is called, (and possibly in a few other code paths), so we'll need to speed that up. Possibly with a Set or Map instead of looping over the actions.

benlesh avatar Sep 07 '22 20:09 benlesh