-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
RTK x100 slower than vanilla Redux at average (up to x400) #4793
Comments
Hmm. This is admittedly slower than I would expect - I would expect an "add item" immer reducer here to take more around 2ms than 6ms. This might be worth looking into. That said, the 100x/400x from your headline here are highly artificial and hopefully never occur in a real application, and that also goes into the whole benchmark a bit: See the style guide in these points: The idea here is that an action should represent an event happening in your application - in almost all situations, those are either user-induced events (clicks), or things like the start or return of a network request. Of course there are exceptions to this - what comes to mind are cases where we've seen Chatbots processing messsages from hundreds of users, or financial dashboards showing real-time data coming in via websocket. These cases can be optimized, or in a single reducer you might actually choose to opt out of immer by just writing a reducer by hand - but these cases make up the 1% of poweruser edge cases, not the 90-95% of users we primarily target and for whom we want to avoid actual real-life bugs. That said - I already started with this: these numbers feel too high by a factor of 3-5 to what I'd expect, and it is worth investigating. Could you maybe adjust the benchmarks to resemble real-life application usage a bit more?
|
About actions per second - I was once participated in a project that had around 100 actions per second - it was a fork of opensource mobile chat app Mattermost, they recently switched to watermelon db (bad solution). Also many projects got lots of actions per second on app launch when fetching lots of stuff. Also, we need to keep in mind that there are mobile devices, and even more, android mobile devices (x10 slower than iOS), and even more old android mobile devices with low battery, so for a good app there should be a pretty big performance reserve for such cases, if comparing to desktop. And actually redux does pretty well in terms of performance. I would say much better than I expected. So it has a great potential in performance, but looks like not with immer. It adds a huge limitations here, and that chatting app would definitely freeze out if someone decided to use it (they used vanilla redux back then), as it already had performance issues due to some very bad decisions like keeping theme in single redux store and many more. So not using redux when it actually could work very well is not cool honestly. There probably are some situations where there can be better solutions, but it is definitely not a chatting app.
Also did some refactoring etc. EDIT: As for making plain reducers - they don't have all this cool boilerplate of slices, so not sure why not just disable immer for them / for slice reducers. Also, I guess there definitely should be a tip in performance doc about that. |
I don't understand what you're saying with this sentence:
As Lenz said: Redux was never intended to be the fastest lib out there. The primary goal is predictability, and accidental mutations go against that. Sure, I wish Immer was faster :) I can see that the majority of the time in your benchmark is being spent in Immer's I know @mweststrate has spent a lot of time trying to optimize it, but also have it be correct in a variety of update situations. Maybe there's still something that could be done to speed it up, maybe there isn't. Might be worth filing a perf issue over in the Immer repo to discuss this. So yeah, in cases where you're using Redux and perf is still critical, you may feel the need to hand-write those reducers. But overall we still see Immer as the right default choice for RTK. |
I've wrote some benchmarks trying to understand how Immer influences the redux performance and got some very strange results:
original
doesn't make much difference.There are probably some mistakes in this code (initially generated by AI), so appreciate some help to find that out.
Here is the code.
To run:
NODE_ENV=production node --expose-gc benchmark.mjs
Environment:
Results:
Data, ms (the lower the better)
Data, x times slower (the lower the better)
Chart, x times slower
PS.
configureStore
andcreateSlice
. Vanilla means usingcreateStore
fromredux
.The text was updated successfully, but these errors were encountered: