Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(reactivity): avoid unnecessary recursion in removeSub #12135

Merged
merged 1 commit into from
Oct 11, 2024

Conversation

skirtles-code
Copy link
Contributor

@skirtles-code skirtles-code commented Oct 9, 2024

I stumbled across an edge case where the performance of computed can go awry:

The time taken grows exponentially with the value of LAYERS. I used 22 in the example, but you may need to tweak it depending on your hardware.

The problem is with cleaning up the subs. removeSub() calls itself recursively if dep.subs is undefined. But in this example, deps.subs is always undefined for all deps, so it ends up calling removeSub() a huge number of times. The same links are being removed over and over.

I've attempted to fix it by additionally checking that deps.subs wasn't already undefined.

The diff makes the change look more complicated than it actually is. I've moved the if (dep.subs === link) { part further down and wrapped it around the clean-up section.

Copy link

pkg-pr-new bot commented Oct 9, 2024

Open in Stackblitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@12135

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@12135

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@12135

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@12135

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@12135

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@12135

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@12135

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@12135

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@12135

vue

pnpm add https://pkg.pr.new/vue@12135

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@12135

commit: b225ac7

Copy link

github-actions bot commented Oct 9, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB (-5 B) 38.1 kB (-1 B) 34.3 kB (+71 B)
vue.global.prod.js 160 kB (-5 B) 58 kB (-1 B) 51.5 kB (-32 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 49.1 kB (-5 B) 18.9 kB (-2 B) 17.3 kB (-1 B)
createApp 55.7 kB (-5 B) 21.4 kB (-2 B) 19.5 kB (-45 B)
createSSRApp 59.7 kB (-5 B) 23.1 kB (-1 B) 21.1 kB (+46 B)
defineCustomElement 60.4 kB (-5 B) 23 kB (-2 B) 20.9 kB (-9 B)
overall 69.4 kB (-5 B) 26.5 kB (-1 B) 24.1 kB (+42 B)

@edison1105
Copy link
Member

/ecosystem-ci run

@vue-bot
Copy link
Contributor

vue-bot commented Oct 10, 2024

📝 Ran ecosystem CI: Open

suite result latest scheduled
language-tools failure failure
nuxt success success
pinia success success
primevue success success
quasar failure success
radix-vue success success
router success success
test-utils success success
vant success success
vite-plugin-vue success success
vitepress success success
vue-i18n success success
vue-macros success success
vuetify success success
vueuse success success
vue-simple-compiler success success

@edison1105
Copy link
Member

/ecosystem-ci run quasar

@vue-bot
Copy link
Contributor

vue-bot commented Oct 10, 2024

📝 Ran ecosystem CI: Open

suite result latest scheduled
quasar success success

@edison1105 edison1105 added ready to merge The PR is ready to be merged. 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. labels Oct 10, 2024
@yyx990803 yyx990803 merged commit ec917cf into vuejs:main Oct 11, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. ready to merge The PR is ready to be merged. scope: reactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants