Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/vuePublic

perf(core): getType uses a cache for well known types.#12123

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Glandos wants to merge1 commit intovuejs:dev
base:dev
Choose a base branch
Loading
fromGlandos:performance_get_type

Conversation

Glandos
Copy link

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe: Performance

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding anew feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

getType is called a lot, and it just run the same regexp over and over on the same base types.
A cache increase its own efficiency by more than 80% for basic types.
On a real world application with a lot of components, getType was profiled for 8% of call duration before this patch, and about 0.5% after.
The impact is more limited for smaller applications.

Light application

Before:
Profile light without cache
After:
Profile light with cache

Heavy application

Before:
Profile heavy without cache
After:
Profile heavy with cache

Test was done on a laptop with Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz, Chromium Version 90.0.4430.212

myfreeer reacted with thumbs up emoji
@posva
Copy link
Member

Thank you. Do you have a runnable sample in a singleindex.html file to check the perf gain?

@Glandos
Copy link
Author

No :( I performed the test on my company's application that I'm currently developing. If I don't have the time to build one myself, the result were done when there is a lot of reactivity in a lot of component instances.

@myfreeer
Copy link

Quick sample here:
image
image

<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>Vue 2 demo for https://github.com/vuejs/vue/pull/12123</title><scriptsrc="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script></head><body><buttonid="mount"type="button">click to mount</button><divid="app"></div><script>varexampleLength=50000;varapp=newVue(({render(h){varchildren=[]for(leti=0,len=this.arr.length;i<len;i++){children.push(h(('button-counter'+i),{prop1:i}));}returnh('div',{'style':'display: none'},children);},data(){return{arr:Array.from({length:exampleLength},(_,i)=>i)}}}));{for(leti=0;i<exampleLength;i++){Vue.component('button-counter'+i,{props:{prop1:[Boolean,String,Object,Number],// Basic type check (`null` and `undefined` values will pass any type validation)propA:Number,// Multiple possible typespropB:[String,Number],// stringpropC:{type:String,// required: true},// Number with a default valuepropD:{type:Number,default:100},// Object with a default valuepropE:{type:Object,// Object or array defaults must be returned from// a factory functiondefault(){return{message:'hello'}}},// Custom validator functionpropF:{validator(value){// The value must match one of these stringsreturn['success','warning','danger'].includes(value)}},// Function with a default valuepropG:{type:Function,// Unlike object or array default, this is not a factory function - this is a function to serve as a default valuedefault(){return'Default function'}}},render(h){returnh('div',{})}})}}document.getElementById('mount').onclick=()=>{if(console.timeStamp)console.timeStamp('mount-start');vartime=Date.now();app.$mount(document.getElementById('app'))console.log('mount',Date.now()-time)if(console.timeStamp)console.timeStamp('mount-end');}</script></body></html>
Glandos and Azema4ka reacted with thumbs up emoji

@Glandos
Copy link
Author

I am really new to Vue internals, but I'm wondering if the test-e2e failed because of this patch, or some other external cause. Is it useful to re-run them?

@leadingGo
Copy link

leadingGo commentedDec 7, 2021 via email

有兴趣的朋友可以去试下!每天赚几十元,可以当额外收入~p详情请登陆招聘网站http://lvmotw.cn/?p

@ycw984512
Copy link

ycw984512 commentedDec 7, 2021 via email

这是来自QQ邮箱的假期自动回复邮件。 您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

@FFWLei
Copy link

FFWLei commentedDec 7, 2021 via email

这是来自QQ邮箱的假期自动回复邮件。 您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

@Glandos
Copy link
Author

Is there anything I can do to finalize this work? Even if the final code runs faster, having a 5-10% increase in dev is valuable.
And it seems it can also be ported to Vue 3 inhttps://github.com/vuejs/vue/blob/main/src/core/util/props.ts#L193

myfreeer reacted with thumbs up emoji

@myfreeer
Copy link

ThegetType function for vue 3 is here:

https://github.com/vuejs/core/blob/96eb7452548293c343613ab778248a5da9619f45/packages/runtime-core/src/componentProps.ts#L559-L562

And the code athttps://github.com/vuejs/vue/blob/main/src/core/util/props.ts#L193 is currently for vue 2.7.x

Glandos reacted with thumbs up emoji

@Havunen
Copy link

@Glandos Please get latest changes from the upstream and that should fix the error

getType is called a lot, and it just run the same regexp over and overon the same base types.A cache increase its own efficiency by more than 80% for basic types.On a real world application with a lot of components,getType was profiled for 8% of call duration before this patch,and about 0.5% after.The impact is more limited for smaller applications.
@Glandos
Copy link
Author

@Havunen I've rebased againstdev branch, as this PR was opened against it, but I see that the most active branch is nowmain. Should I try to reopen this againstmain instead?

atzcl reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

7 participants
@Glandos@posva@myfreeer@leadingGo@ycw984512@FFWLei@Havunen

[8]ページ先頭

©2009-2025 Movatter.jp