| CARVIEW |
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 865
Releases: immerjs/immer
v11.1.3
570c800v11.1.2
Assets 2
v11.1.0
11.1.0 (2025-12-20)
This feature release adds a new optional "array method overrides" plugin that significantly speeds up array methods when accessing drafts.
Changelog
Performance Improvements
As part of the recent performance optimization work, our benchmarks showed that all Proxy-based immutable update libraries were drastically slower than vanilla JS when calling both mutating and non-mutating array methods. After investigation, it turns out that an array method like arr.filter() causes the Proxy's get trap to trigger for every single item in the array. This in turn forces creation of a new Proxy and internal Immer metadata for every item, even though this was just a read operation and no items were being updated.
This release adds a new enableArrayMethods plugin that will override draft array methods to bypass the draft and directly operate on the underlying wrapped array instance. This significantly speeds up array operations.
When enabled, the plugin overrides these array methods:
- Mutating:
push,pop,shift,unshift,splice,reverse,sort - Non-mutating:
filter,slice,concat,flat,find,findIndex,findLast,findLastIndex,some,every,indexOf,lastIndexOf,includes,join,toString,toLocaleString
Our benchmarks show that the overridden methods (plus the other perf changes in Immer 10.2 and 11.0) are 50-80% faster than the baseline behavior of Immer 10.1.
The plugin adds about 1.5-2K minified to Immer's bundle size.
It's important to note that the plugin does change the "safe to mutate a draft" semantics of Immer. Any of these methods that receives an array item as a callback argument will not automatically wrap that item in a Proxy!. That means that if you try to mutate an argument in a method such as filter, it will actually mutate the real underlying object, which will cause bugs in your app. This is an intentional design tradeoff. Semantically, all of these methods imply read-only access to array values, so if your code tries to mutate an array item in a callback, that is a bug in your code.
Note that this does not override map, flatMap, forEach, or reduce / reduceRight. Those methods do imply either side effects and potential mutations, or returning arbitrary values. Given that, we determined it was both safest and simplest to keep their behavior as-is.
See the Array Methods Plugin docs page for further details on the behavior of the overridden methods.
What's Changed
- Override array methods to avoid proxy creation while iterating and updating by @markerikson in #1184
Assets 2
v11.0.1
Assets 2
v11.0.0
d6c120211.0.0 (2025-11-23)
Performance Improvements
BREAKING CHANGES
-
enable loose iteration by default
-
Simplify some iteration checks
-
Allow passing type to get/set utils to skip archetype lookup
-
Convert assigned_ to Map
-
Enable loose iteration
-
Replace recursive tree finalization with targeted callbacks
Ported Mutative's "finalization callback" approach as a more targeted and performant implementation for finalization compared to the existing recursive tree traversal approach:
- Added cleanup callbacks for each draft that's created
- Added callbacks to handle root drafts, assigned values, and recursing
inside of plain values - Updated state creation to return [draft, state] to avoid a lookup
- Rewrote patch generation system to work with callbacks instead of
during tree traversal
- Update self-reference test with new behavior
- Apply code review suggestions
- Byte-shave scopes and patch plugin usage
- Inline finalizeAssigned
- Move fixPotentialSetContents to plugin
- Byte-shave typeof utils
- Byte-shave Object references
- Byte-shave field names and arrow functions
Assets 2
v10.2.0
e1996ceAssets 2
v10.1.3
85faaa2Assets 2
v10.1.2
062210ev10.1.1
e2d222bv10.1.0
53e320310.1.0 (2024-04-27)
Features
- performance: Make non-strict mode faster for classes. Addresses #1071 (53e3203). Immer 10.x solved slow iteration for plain JS objects. This update applies the same handling to class instances. In cases this makes class instance handling 3 times faster. Note that this slightly modifies the behavior of Immer with classes in obscure corner cases, in ways that match current documentation, but do not match previous behavior. If you run into issues with this release icmw. class instances, use
setUseStrictShallowCopy("class_only")to revert to the old behavior. For more details see https://immerjs.github.io/immer/complex-objects#semantics-in-detail