Skip to content

Commit e9eb162

Browse files
authored
Merge pull request #14 from vuejs/2.0
2.0
2 parents d657f24 + c50762f commit e9eb162

File tree

12 files changed

+272
-261
lines changed

12 files changed

+272
-261
lines changed

src/guide/comparison.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,51 @@ When rendering UI, manipulating the DOM is typically the most expensive operatio
3333

3434
In React, let's say the additional overhead of rendering an element is 1 and the overhead of an average component is 2. In Vue, the overhead of an element would be more like 0.1, but the overhead of an average component would be 4, due to the setup required for our reactivity system.
3535

36-
This means that in typical applications, where there are many more elements than components being rendered, Vue will outperform React by a significant margin. To demonstrate this, let's render a list of 10,000 items in a single component. In Chrome 52 on my 2014 Macbook Air, [Vue renders](https://jsfiddle.net/chrisvfritz/859gL422/) in an average of 60ms, while [React renders](https://jsfiddle.net/chrisvfritz/65ojbkab/) in an average of 127ms.
37-
38-
In extreme cases however, such as using 1 normal component to render each element, Vue will usually be slower. When modifying the previous examples accordingly, [Vue renders](https://jsfiddle.net/chrisvfritz/mk8jaqpg/) in ~585ms, while [React renders](https://jsfiddle.net/chrisvfritz/2sx0341o/) in ~157ms! This isn't the end of the story though. Both Vue and React offer functional components, which are preferred in situations like this. Since functional components are closer to the cost of elements, Vue is once again on top, with [~73ms](https://jsfiddle.net/chrisvfritz/413wjqyf/) vs [~144ms](https://jsfiddle.net/chrisvfritz/kss01xg7/) - and this performance boost only required adding a single line for Vue: `functional: true`.
36+
This means that in typical applications, where there are many more elements than components being rendered, Vue will outperform React by a significant margin. In extreme cases however, such as using 1 normal component to render each element, Vue will usually be slower. This isn't the end of the story though.
37+
38+
Both Vue and React also offer functional components, which are stateless and instanceless - and therefore, require less overhead. When these are used in performance-critical situations, Vue is once again faster. To demonstrate this, we built a simple [benchmark project](https://github.com/chrisvfritz/vue-render-performance-comparisons) that just renders 10,000 list items 100 times. We encourage you to try it yourself, as the results will vary depending on the hardware and browser used - and actually, they'll vary even between runs due to the nature of JavaScript engines.
39+
40+
If you're feeling lazy though, below are the numbers from one run in Chrome 52 on a 2014 MacBook Air. To avoid cherry-picking, both benchmarks were actually run 20 separate times, with results from the best runs included below:
41+
42+
{% raw %}
43+
<table class="benchmark-table">
44+
<thead>
45+
<tr>
46+
<th></th>
47+
<th>Vue</th>
48+
<th>React</th>
49+
</tr>
50+
</thead>
51+
<tbody>
52+
<tr>
53+
<th>Fastest</th>
54+
<td>23ms</td>
55+
<td>63ms</td>
56+
</tr>
57+
<tr>
58+
<th>Median</th>
59+
<td>42ms</td>
60+
<td>81ms</td>
61+
</tr>
62+
<tr>
63+
<th>Average</th>
64+
<td>51ms</td>
65+
<td>94ms</td>
66+
</tr>
67+
<tr>
68+
<th>95th Perc.</th>
69+
<td>73ms</td>
70+
<td>164ms</td>
71+
</tr>
72+
<tr>
73+
<th>Slowest</th>
74+
<td>343ms</td>
75+
<td>453ms</td>
76+
</tr>
77+
</tr>
78+
</tbody>
79+
</table>
80+
{% endraw %}
3981

4082
#### Update Performance
4183

@@ -162,7 +204,7 @@ React is renowned for its steep learning curve. Before you can really get starte
162204
While Vue scales up just as well as, if not better than React, it also scales down just as well as jQuery. That's right - all you have to do is drop a single script tag into a page:
163205

164206
``` html
165-
<script src="https://npmcdn.com/vue@next/dist/vue.js"></script>
207+
<script src="https://unpkg.com/vue@next/dist/vue.js"></script>
166208
```
167209

168210
Then you can start writing Vue code and even ship the minified version to production without feeling guilty or having to worry about performance problems.

src/guide/computed.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ For example:
171171
<!-- and collections of general-purpose utility methods, Vue core -->
172172
<!-- is able to remain small by not reinventing them. This also -->
173173
<!-- gives you the freedom to just use what you're familiar with. -->
174-
<script src="https://npmcdn.com/axios@0.12.0/dist/axios.min.js"></script>
175-
<script src="https://npmcdn.com/lodash@4.13.1/lodash.min.js"></script>
174+
<script src="https://unpkg.com/axios@0.12.0/dist/axios.min.js"></script>
175+
<script src="https://unpkg.com/lodash@4.13.1/lodash.min.js"></script>
176176
<script>
177177
var watchExampleVM = new Vue({
178178
el: '#watch-example',
@@ -203,7 +203,7 @@ var watchExampleVM = new Vue({
203203
return
204204
}
205205
vm.answer = 'Thinking...'
206-
axios.get('http://yesno.wtf/api')
206+
axios.get('https://yesno.wtf/api')
207207
.then(function (response) {
208208
vm.answer = _.capitalize(response.data.answer)
209209
})
@@ -230,8 +230,8 @@ Result:
230230
</p>
231231
<p>{{ answer }}</p>
232232
</div>
233-
<script src="https://npmcdn.com/axios@0.12.0/dist/axios.min.js"></script>
234-
<script src="https://npmcdn.com/lodash@4.13.1/lodash.min.js"></script>
233+
<script src="https://unpkg.com/axios@0.12.0/dist/axios.min.js"></script>
234+
<script src="https://unpkg.com/lodash@4.13.1/lodash.min.js"></script>
235235
<script>
236236
var watchExampleVM = new Vue({
237237
el: '#watch-example',
@@ -254,7 +254,7 @@ var watchExampleVM = new Vue({
254254
return
255255
}
256256
vm.answer = 'Thinking...'
257-
axios.get('http://yesno.wtf/api')
257+
axios.get('https://yesno.wtf/api')
258258
.then(function (response) {
259259
vm.answer = _.capitalize(response.data.answer)
260260
})

0 commit comments

Comments
 (0)