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

Initial Render slightly slower than Vue 2 in Vue-CLI base app. #3090

Closed
techbirds opened this issue Jan 25, 2021 · 9 comments
Closed

Initial Render slightly slower than Vue 2 in Vue-CLI base app. #3090

techbirds opened this issue Jan 25, 2021 · 9 comments
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf.

Comments

@techbirds
Copy link

techbirds commented Jan 25, 2021

Environment

Chrome 88.0.4324.96(正式版本) (x86_64)
iMac (Retina 5K, 27-inch, 2017)
Mac OS Mojave
Vue CLI 4.5.9
Node.js 12.13.1

Version

3.0.0

Reproduction link

https://github.com/techbirds/learn-vue

Code Preivew

<template>
  <div id="app">
    <!-- <img alt="Vue logo" src="./assets/logo.png"> -->
    <HelloWorld msg="Welcome to Your Vue.js App" v-for="n in 3000" :key="n"/>
  </div>
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'

export default {
  name: 'App',
  components: {
    HelloWorld
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

Steps to reproduce

1、use vue cli to create v3 app and v2 app
2、render HelloWorlds component 3000 times
3、watch performance with chrome devtools。
v2 perf:
image

v3 perf:

image

project link:

https://github.com/techbirds/learn-vue/tree/master/vue2-demo
https://github.com/techbirds/learn-vue/tree/master/vue3-demo

What is expected?

v3 faster than v2

What is actually happening?

The speed is about the same, even slower than v2

@posva
Copy link
Member

posva commented Jan 25, 2021

Tested with a project using vite and vue 3 and then the same components using vue-cli with vue 2, after bundling in prod mode.

Vue 3

vue 3

Vue 2
vue 2

You can find other benchmarks at https://github.com/krausest/js-framework-benchmark

@posva posva closed this as completed Jan 25, 2021
@LinusBorg
Copy link
Member

Just to add: it doesn't make too much sense to compare performance in development mode (npm run serve). Vue 3 could very well be a tad slower as Vue 2, but that would not matter unless it was so bad that it slowed down your development work, which it isn't.

What's important is the production build.

@techbirds
Copy link
Author

1、on the production build with npm run build
2、run as http-server

v2 perf:

image
image

v3 perf:

image
image

v3 performance slower than v2.

please tell me why ? Is the test posture wrong?

@techbirds
Copy link
Author

Tested with a project using vite and vue 3 and then the same components using vue-cli with vue 2, after bundling in prod mode.

Vue 3

vue 3

Vue 2
vue 2

You can find other benchmarks at https://github.com/krausest/js-framework-benchmark

Can you provide code samples and test procedures?

@posva
Copy link
Member

posva commented Jan 26, 2021

I used the code generated by yarn create @vitejs/app and migrated it to options api with Vue CLI and Vue 2 to compare. As @LinusBorg pointed out in discussions, it could be related to differences between the bundling (webpack vs rollup). Maybe there is something to improve here but not sure where

@posva posva reopened this Jan 26, 2021
@techbirds
Copy link
Author

Test:

without webpack bundle. run with only vue framework.

v2

image
image

v3

image
image

Phenomenon:

  1. Based on the production build of vue cli, the running performance of v2 and v3 is very close
  2. Based on pure HTML online template compilation and construction:
    1. The running performance of v3 is much better on prod than v2 prod
    2. The development version of v3 is very close to the prod version of v2
    3. There is a certain gap in performance between the development version of v2 and the prod version of v2, but it is obviously not as big as the gap between v3

Problem:

  1. Why is the production build performance based on vue cli so poor?
  2. What is the difference between the production and development versions of v3? Why is the performance poor so bad?

Code Sample:

https://github.com/techbirds/learn-vue/blob/master/html/index.v2.html
https://github.com/techbirds/learn-vue/blob/master/html/index.v3.html

@LinusBorg LinusBorg changed the title why vue3 not faster than v2 Initial Render slightly slower than Vue 2 in Vue-CLI base app. Jan 28, 2021
@LinusBorg
Copy link
Member

Noteworthy is that this is only looking at the initial render. Efficiency of updates is another, arguably maybe more important thing for performance.

Also, on the upside, this shows how mouch more efficient Vue 3 is memory-wise. In these measurements, memory consumption is cut in half compared to Vue 2.

@yyx990803 yyx990803 added the ❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. label May 28, 2021
@yyx990803
Copy link
Member

Investigated a bit and turns out the perf bottleneck is due to static content insertion. The component is largely static so it compiles into a single static node with an HTML string. When mounting such a node, we are currently setting it as innerHTML of a temp container and then move the created nodes into the mount target. Turns out this is actually much slower than just normal VDOM mounting. We will need to adjust either the static insertion logic or the stringification strategy. It is still important for SSR hydration performance.

@yyx990803
Copy link
Member

Vue 2

Screen Shot 2021-06-21 at 2 36 59 PM

Vue 3 before fix

Screen Shot 2021-06-21 at 2 36 03 PM

Vue 3 after fix

Screen Shot 2021-06-21 at 2 37 37 PM

@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf.
Projects
None yet
Development

No branches or pull requests

4 participants