Skip to content

Commit d8a894a

Browse files
committed
Specifically disable Immer strict iteration for perf
1 parent 98de804 commit d8a894a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/toolkit/src/createReducer.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import type { Draft } from 'immer'
2-
import { produce as createNextState, isDraft, isDraftable } from 'immer'
2+
import {
3+
produce as createNextState,
4+
isDraft,
5+
isDraftable,
6+
setUseStrictIteration,
7+
} from 'immer'
38
import type { Action, Reducer, UnknownAction } from 'redux'
49
import type { ActionReducerMapBuilder } from './mapBuilders'
510
import { executeReducerBuilderCallback } from './mapBuilders'
611
import type { NoInfer, TypeGuard } from './tsHelpers'
712
import { freezeDraftable } from './utils'
813

14+
// Immer 10.2 defaults to still using strict iteration (specifically
15+
// `Reflect.ownKeys()` for symbols support). However, we assume that
16+
// Redux users are not using symbols as state keys, so we'll override
17+
// this to prefer `Object.keys()` instead, as it provides a ~10% speedup.
18+
// If users do need symbol support, they can call `setUseStrictIteration(true)` themselves.
19+
setUseStrictIteration(false)
20+
921
/**
1022
* Defines a mapping from action types to corresponding action object shapes.
1123
*

0 commit comments

Comments
 (0)