-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
chore(runtime-core): use new Array.fill to populate array #319
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
Conversation
It's faster because Array length is settled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is even faster (and won't require a polyfill when we do IE11 support):
const newIndextoOldIndexMap = new Array(toBePatched)
for (i = 0; i < toBePatched; i++) newIndexToOldIndexMap[i] = 0
on chrome seems not to be as fast 🤔 https://jsperf.com/array-generate-and-populate EDIT: |
Kinda equal https://jsperf.com/array-fill-vs-loop |
I'm concern on how our benchmarks are yielding different results 🤔 |
You last test assigns to |
@pikax your tests are using a global There's no other places that need this so no need for extraction. |
Nice catch, I copied the code from the source code, probably better as you said @yyx990803 |
Hey @pikax, thank you for your time and effort spent on this PR, contributions like yours help make Vue better for everyone. Cheers! 💚 |
* chore: Remove unnecessary console.log (vuejs#312) * types: improve typing (vuejs#313) * types: improve typing (vuejs#309) * perf(v-for): use faster array population in renderList * refactor(compiler-core): avoid has call (vuejs#314) * feat(compiler-core): do not generate TEXT flag if child is constant * perf(runtime-core): use faster diff map population (vuejs#319) * feat(compiler-core/v-model): avoid patching v-model handler when possible * feat(compiler-core/v-model): error when v-model is used on scope variable * feat(compiler-core/v-model): generate modelModifiers for component v-model * feat(compiler-core/v-slot): only force dynamic slots when referencing scope vars This feature is only applied with prefixIdentifiers: true. * perf: skip hasScopeRef check if there are no scope vars * build(deps-dev): bump lerna from 3.18.0 to 3.18.1 Bumps [lerna](https://github.com/lerna/lerna/tree/HEAD/core/lerna) from 3.18.0 to 3.18.1. - [Release notes](https://github.com/lerna/lerna/releases) - [Changelog](https://github.com/lerna/lerna/blob/master/core/lerna/CHANGELOG.md) - [Commits](https://github.com/lerna/lerna/commits/v3.18.1/core/lerna) Signed-off-by: dependabot-preview[bot] <[email protected]> * feat: emit compiler error for invalid JavaScript expressions * feat(compiler-core): support Suspense in templates * fix(runtime-core): handle dynamicChildren when portal is used as a block * chore: typos [ci-skip] (vuejs#323) * perf: revert to _isRef for perf Benchmarking shows checking for a plain property is about 4~5x faster than checking for a Symbol, likely because the Symbol does not fit well into V8's hidden class model. * perf(core): cache property access types on renderProxy * perf: minor tweaks * test(compiler-core): add test for custom delimiter (vuejs#315) * refactor(runtime-core): extract promise check into shared (vuejs#325) * perf: further tweak accessCache
using Array.fill seems a bit faster than looping.
Array.fill is not supported on IE maybe use a polyfill when the time comes?