diff --git a/packages/mobx/src/core/derivation.ts b/packages/mobx/src/core/derivation.ts index 66e535312..8eea4afa3 100644 --- a/packages/mobx/src/core/derivation.ts +++ b/packages/mobx/src/core/derivation.ts @@ -167,9 +167,12 @@ export function checkIfStateReadsAreAllowed(observable: IObservable) { export function trackDerivedFunction(derivation: IDerivation, f: () => T, context: any) { const prevAllowStateReads = allowStateReadsStart(true) changeDependenciesStateTo0(derivation) - // pre allocate array allocation + 20% extra room for variation in deps - // array will be trimmed by bindDependencies - derivation.newObserving_ = new Array(Math.ceil(derivation.observing_.length * 1.2)) + // Preallocate array; will be trimmed by bindDependencies. + derivation.newObserving_ = new Array( + derivation.observing_.length + ? Math.ceil(derivation.observing_.length * 1.2) // 20% extra room for variation in deps + : 100 // Establishing initial dependencies, preallocate constant space. + ) derivation.unboundDepsCount_ = 0 derivation.runId_ = ++globalState.runId const prevTracking = globalState.trackingDerivation