Skip to content

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

Merged
merged 2 commits into from
Oct 16, 2019

Conversation

pikax
Copy link
Member

@pikax pikax commented Oct 16, 2019

using Array.fill seems a bit faster than looping.

Array.fill is not supported on IE maybe use a polyfill when the time comes?

@CyberAP
Copy link
Contributor

CyberAP commented Oct 16, 2019

using Array.fill seems a bit faster than looping.

It's faster because Array length is settled.

Copy link
Member

@yyx990803 yyx990803 left a 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

@pikax
Copy link
Member Author

pikax commented Oct 16, 2019

on chrome seems not to be as fast 🤔

https://jsperf.com/array-generate-and-populate

EDIT:

chrome:
image

safary:
image

@CyberAP
Copy link
Contributor

CyberAP commented Oct 16, 2019

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

Kinda equal https://jsperf.com/array-fill-vs-loop

@pikax
Copy link
Member Author

pikax commented Oct 16, 2019

I'm concern on how our benchmarks are yielding different results 🤔

@CyberAP
Copy link
Contributor

CyberAP commented Oct 16, 2019

I'm concern on how our benchmarks are yielding different results 🤔

You last test assigns to window.i

@CyberAP
Copy link
Contributor

CyberAP commented Oct 16, 2019

By the way right now fill is hilariously slow in Firefox.

Maybe it'd be better to extract that into a shared function? Although I don't know if there are any more places where a fixed array is filled.

image

@yyx990803
Copy link
Member

yyx990803 commented Oct 16, 2019

@pikax your tests are using a global i, which incurs a global variable check on every i access.

There's no other places that need this so no need for extraction.

@pikax
Copy link
Member Author

pikax commented Oct 16, 2019

Nice catch, I copied the code from the source code, probably better as you said @yyx990803

@yyx990803 yyx990803 merged commit 48b79d0 into vuejs:master Oct 16, 2019
@vue-bot
Copy link
Contributor

vue-bot commented Oct 16, 2019

Hey @pikax, thank you for your time and effort spent on this PR, contributions like yours help make Vue better for everyone. Cheers! 💚

jackiecookie added a commit to jackiecookie/vue-next that referenced this pull request Oct 18, 2019
* 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
@pikax pikax deleted the runtime_1 branch August 15, 2021 09:12
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.

4 participants