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): high efficiency effect() #8043

Closed
wants to merge 43 commits into from

Conversation

johnsoncodehk
Copy link
Member

@johnsoncodehk johnsoncodehk commented Apr 6, 2023

This PR uses the same way as #5912 to minimize effect() callback called times.

For the following code, times were reduced from 20001 to 167.

let times = 0

const sec = ref(0)
const min = computed(() => {
  return Math.floor(sec.value / 60)
})
const hour = computed(() => {
  return Math.floor(min.value / 60)
})

effect(() => {
  times++
  min.value
  hour.value
})

for (sec.value = 0; sec.value < 10000; sec.value++) { }

console.log('min:', min.value, 'hour:', hour.value) // min: 166 hour: 2
console.log(times) // 20001 -> 167

@vercel
Copy link

vercel bot commented Apr 6, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
sfc-playground ⬜️ Ignored (Inspect) Apr 7, 2023 1:31pm

@johnsoncodehk johnsoncodehk marked this pull request as ready for review April 7, 2023 13:21
@johnsoncodehk johnsoncodehk changed the title perf(reactivity): trigger effect() callback on-demand perf(reactivity): high efficiency effect() Jul 17, 2023
@johnsoncodehk
Copy link
Member Author

Combine to #5912.

@johnsoncodehk johnsoncodehk deleted the effect-ondemand branch August 14, 2023 05:47
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.

2 participants