Skip to content

perf(core): improve vdom diffing by removing unnecessary conditional statement in getSequence function #3928

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

xxgjzftd
Copy link
Contributor

Here is some simple explanation for this pr.
For the removal of conditional statement if (arrI < arr[result[u]]):
Before the while loop at line 2479, the arrI variable always less than the last item of the result array,
so after this loop, arrI always less than the result[v],
and after this loop, the v always equals to u,
so we don't need the arrI < arr[result[u]] statement.

For the result array init const result = []:
Actually, this change make the result variable different from original,but it don't effect the children patch result.
Original getSequence([0, 1, 8, 7, 9, 5]) will be[0, 1, 3, 4], now it's [1, 3, 4].

Copy link

github-actions bot commented Sep 9, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 100 kB (-14 B) 37.7 kB (-9 B) 34 kB (-37 B)
vue.global.prod.js 159 kB (-14 B) 57.6 kB (-9 B) 51.2 kB (-5 B)

Usages

Name Size Gzip Brotli
createApp 55.4 kB (-14 B) 21.3 kB (-11 B) 19.4 kB (-17 B)
createSSRApp 59.3 kB (-14 B) 23 kB (-7 B) 20.9 kB (+57 B)
defineCustomElement 60.1 kB (-14 B) 22.8 kB (-13 B) 20.7 kB (-11 B)
overall 69.1 kB (-14 B) 26.3 kB (-6 B) 24 kB (+53 B)
Copy link

pkg-pr-new bot commented Sep 9, 2024

Open in Stackblitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

@vue/compat

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

vue

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

commit: 46e0d4e

@edison1105 edison1105 added 🍰 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. labels Sep 9, 2024
Copy link
Contributor

@skirtles-code skirtles-code left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made an attempt at benchmarking this:

where:

  • getSequence is the existing implementation.
  • getSequence2 is the implementation in this PR.
  • getSequence3 removes the conditional but leaves the const result = [0] unchanged.

Running that benchmark in both Chrome and Firefox, it seems that getSequence2 is fairly consistently slower than getSequence.

getSequence3 is about the same as getSequence, though getSequence3 is marginally faster.

Perhaps I'm missing something, but it seems that changing const result = [0] to const result = [] has actually made things slower.

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.
3 participants