Skip to content

perf(observer): add early return in Dep.notify() when subs is empty - #13369

Open
ifer47 wants to merge 1 commit into
vuejs:mainfrom
ifer47:perf/dep-notify-early-return
Open

perf(observer): add early return in Dep.notify() when subs is empty#13369
ifer47 wants to merge 1 commit into
vuejs:mainfrom
ifer47:perf/dep-notify-early-return

Conversation

@ifer47

@ifer47 ifer47 commented Jun 16, 2026

Copy link
Copy Markdown

Summary

  • Add an early return in Dep.notify() when the filtered subscriber list is empty
  • After filtering out null subscribers, if no active subscribers remain, return immediately
  • Avoids unnecessary sorting (in dev sync mode) and zero-iteration loop

Problem

In Dep.notify(), after filtering null subscribers with this.subs.filter(s => s), the method proceeds even when the resulting subs array is empty. This means in dev sync mode, it will unnecessarily sort an empty array, and then enter a zero-iteration for loop.

Changes

Added if (subs.length === 0) return after the subs filtering in Dep.notify().

Closes #13019

🤖 Generated with Claude Code Best

After filtering out null subscribers, if no subscribers remain,
return early to avoid unnecessary sorting (in dev sync mode) and
loop iteration. This avoids creating an empty sorted array and
entering a zero-iteration loop.

Closes vuejs#13019

Co-Authored-By: zhipu/glm-5 <zai-org@claude-code-best.win>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In notify, why is the return not checked when subs is empty

1 participant