-
-
Notifications
You must be signed in to change notification settings - Fork 849
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
Performance of mutating large collections: arrays vs objects #649
Performance of mutating large collections: arrays vs objects #649
Comments
Sorry, didn't really have time to look into it so far. Some things to check:
|
thanks Michel, I'll drop a comment here when I arrive at a solution I'm happy with. |
BREAKING CHANGE: always freeze by default, even in production mode. Use `setAutoFreeze(process.env.NODE_ENV !== 'production')` for the old behavior. See #687 (comment) for the rationale. Fixes #649, #681, #687
🎉 This issue has been resolved in version 8.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This is the top result on Google for Immer arrays vs. objects benchmarking so sharing info here in case it's useful for future readers. Thanks @keriwarr for the benchmarking scripts. I just tried them with Immer 10 to see if there's still a performance difference between array and object. Seems like there is, but much reduced. I just changed Immer to 10.0.3 and removed
and
so it seems like it's still worth using arrays w/o autofreezing for large performance-critical applications that need Immer. Hope this is helpful for anyone else looking into Immer performance. |
🙋♂ Question
Hello!
When I first read the immer performance docs, it didn't occur to me at the time that choice of Array vs Object for storing data might make a large impact on performance.
I use
immer
to manage a redux store in which records are keyed by their ID inside of an object. This performs perfectly well when the number of records is in the low 1000s, however we are looking to push our application to the level of supporting tens or possibly even hundreds of thousands of records. What I've found is that for sufficiently large collections it can take vastly longer to update a single record if the collection is an object as opposed to an array.Link to repro
https://codesandbox.io/s/immer-sandbox-g64y4
In this demo, I create an array collection and an object collection of todos (just like in the
test:perf
code) but each with size 200,000, and then measure the time it takes to update a single record within the collection.Update:
Map
s seem to be about an order of magnitude faster than objects but still a few times slower than arrays (I tried out a few different collection sizes). However, I don't think that I would want to take the hit of using an unserializable data structure in redux.https://codesandbox.io/s/immer-sandbox-09zyb
Environment
We only accept questions against the latest Immer version.
setUseProxies(true)
setUseProxies(false)
(ES5 only)P.S. thanks for this awesome package <3
The text was updated successfully, but these errors were encountered: