Skip to content

Commit

Permalink
perf(reactivity): cache tracking value (vuejs#11145)
Browse files Browse the repository at this point in the history
  • Loading branch information
jh-leong authored Jun 22, 2024
1 parent 8c4d7f5 commit 7936dae
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,19 @@ export function triggerEffects(
) {
pauseScheduling()
for (const effect of dep.keys()) {
// dep.get(effect) is very expensive, we need to calculate it lazily and reuse the result
let tracking: boolean | undefined

if (!dep.computed && effect.computed) {
if (dep.get(effect) === effect._trackId && effect._runnings > 0) {
if (
effect._runnings > 0 &&
(tracking ??= dep.get(effect) === effect._trackId)
) {
effect._dirtyLevel = DirtyLevels.MaybeDirty_ComputedSideEffect_Origin
continue
}
}
// dep.get(effect) is very expensive, we need to calculate it lazily and reuse the result
let tracking: boolean | undefined

if (
effect._dirtyLevel < dirtyLevel &&
(tracking ??= dep.get(effect) === effect._trackId)
Expand Down

0 comments on commit 7936dae

Please sign in to comment.