Skip to content

Commit d0bc1a1

Browse files
committed
perf: fast path for first time gets the computed value
1 parent 3713a4d commit d0bc1a1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export function computed<T>(getter: (previousValue?: T) => T): () => T {
128128
subsTail: undefined,
129129
deps: undefined,
130130
depsTail: undefined,
131-
flags: 17 as ReactiveFlags.Mutable | ReactiveFlags.Dirty,
131+
flags: 0 satisfies ReactiveFlags.None,
132132
getter: getter as (previousValue?: unknown) => unknown,
133133
}) as () => T;
134134
}
@@ -272,6 +272,14 @@ function computedOper<T>(this: Computed<T>): T {
272272
shallowPropagate(subs);
273273
}
274274
}
275+
} else if (!flags) {
276+
this.flags = 1 satisfies ReactiveFlags.Mutable;
277+
const prevSub = setCurrentSub(this);
278+
try {
279+
this.value = this.getter();
280+
} finally {
281+
activeSub = prevSub;
282+
}
275283
}
276284
const sub = activeSub;
277285
if (sub !== undefined) {

0 commit comments

Comments
 (0)