-
-
Notifications
You must be signed in to change notification settings - Fork 861
Description
🐛 Bug Report
Immer takes a long time to update the data.
Link to repro
To Reproduce
Chrome console:
console.time('create');
const dataSource = Object.fromEntries(
[...Array(4000).keys()].map((key) => [key, { key, data: { value: key } }]),
);
console.timeEnd('create');
console.time('update');
const result = produce(dataSource, (draft) => {
draft[1000].data.value = 100;
});
console.timeEnd('update');
Observed behavior
I checked the source code, the problem is in shallowCopy
。If you use Object.assign
instead, there is no performance problem
Time-consuming code:
...
const descriptors = getOwnPropertyDescriptors(base)
...
return Object.create(Object.getPrototypeOf(base), descriptors)
Expected behavior
Time shouldn't be so long
Environment
We only accept bug reports against the latest Immer version.
- Immer version:
- I filed this report against the latest version of Immer
- Occurs with
setUseProxies(true)
- Occurs with
setUseProxies(false)
(ES5 only)