A place to cache linked articles (think custom and personal wayback machine)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. <!doctype html><!-- This is a valid HTML5 document. -->
  2. <!-- Screen readers, SEO, extensions and so on. -->
  3. <html lang="fr">
  4. <!-- Has to be within the first 1024 bytes, hence before the <title>
  5. See: https://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#charset -->
  6. <meta charset="utf-8">
  7. <!-- Why no `X-UA-Compatible` meta: https://stackoverflow.com/a/6771584 -->
  8. <!-- The viewport meta is quite crowded and we are responsible for that.
  9. See: https://codepen.io/tigt/post/meta-viewport-for-2015 -->
  10. <meta name="viewport" content="width=device-width,initial-scale=1">
  11. <!-- Required to make a valid HTML5 document. -->
  12. <title>The Cost of Javascript Frameworks (archive) — David Larlet</title>
  13. <meta name="description" content="Publication mise en cache pour en conserver une trace.">
  14. <!-- That good ol' feed, subscribe :). -->
  15. <link rel="alternate" type="application/atom+xml" title="Feed" href="/david/log/">
  16. <!-- Generated from https://realfavicongenerator.net/ such a mess. -->
  17. <link rel="apple-touch-icon" sizes="180x180" href="/static/david/icons2/apple-touch-icon.png">
  18. <link rel="icon" type="image/png" sizes="32x32" href="/static/david/icons2/favicon-32x32.png">
  19. <link rel="icon" type="image/png" sizes="16x16" href="/static/david/icons2/favicon-16x16.png">
  20. <link rel="manifest" href="/static/david/icons2/site.webmanifest">
  21. <link rel="mask-icon" href="/static/david/icons2/safari-pinned-tab.svg" color="#07486c">
  22. <link rel="shortcut icon" href="/static/david/icons2/favicon.ico">
  23. <meta name="msapplication-TileColor" content="#f0f0ea">
  24. <meta name="msapplication-config" content="/static/david/icons2/browserconfig.xml">
  25. <meta name="theme-color" content="#f0f0ea">
  26. <!-- Documented, feel free to shoot an email. -->
  27. <link rel="stylesheet" href="/static/david/css/style_2020-06-19.css">
  28. <!-- See https://www.zachleat.com/web/comprehensive-webfonts/ for the trade-off. -->
  29. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  30. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  31. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  32. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  33. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  34. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  35. <script type="text/javascript">
  36. function toggleTheme(themeName) {
  37. document.documentElement.classList.toggle(
  38. 'forced-dark',
  39. themeName === 'dark'
  40. )
  41. document.documentElement.classList.toggle(
  42. 'forced-light',
  43. themeName === 'light'
  44. )
  45. }
  46. const selectedTheme = localStorage.getItem('theme')
  47. if (selectedTheme !== 'undefined') {
  48. toggleTheme(selectedTheme)
  49. }
  50. </script>
  51. <meta name="robots" content="noindex, nofollow">
  52. <meta content="origin-when-cross-origin" name="referrer">
  53. <!-- Canonical URL for SEO purposes -->
  54. <link rel="canonical" href="https://timkadlec.com/remembers/2020-04-21-the-cost-of-javascript-frameworks/">
  55. <body class="remarkdown h1-underline h2-underline h3-underline hr-center ul-star pre-tick">
  56. <article>
  57. <header>
  58. <h1>The Cost of Javascript Frameworks</h1>
  59. </header>
  60. <nav>
  61. <p class="center">
  62. <a href="/david/" title="Aller à l’accueil">🏠</a> •
  63. <a href="https://timkadlec.com/remembers/2020-04-21-the-cost-of-javascript-frameworks/" title="Lien vers le contenu original">Source originale</a>
  64. </p>
  65. </nav>
  66. <hr>
  67. <main>
  68. <p>There is no faster (pun intended) way to slow down a site than to use a bunch of JavaScript.</p>
  69. <p>The thing about JavaScript is you end up paying a performance tax no less than four times:</p>
  70. <ol>
  71. <li>The cost of downloading the file on the network</li>
  72. <li>The cost of parsing and compiling the uncompressed file once downloaded</li>
  73. <li>The cost of executing the JavaScript</li>
  74. <li>The memory cost</li>
  75. </ol>
  76. <p>The <a href="https://v8.dev/blog/cost-of-javascript-2019">combination is very expensive</a>.</p>
  77. <p>And we are shipping an increasingly high amount. We’re making the core functionality of our sites increasingly dependant on JavaScript as organizations move towards sites driven by frameworks like React, Vue.js, and friends.</p>
  78. <p>I see a lot of very heavy sites using them, but then, my perspective is very biased as the companies that I work with work with me precisely <em>because</em> they are facing performance challenges. I was curious just how common the situation is and just <em>how</em> much of a penalty we’re paying when we make these frameworks the default starting point.</p>
  79. <p>Thanks to <a href="https://httparchive.org">HTTP Archive</a>, we can figure that out.</p>
  80. <h2 id="the-data">The data</h2>
  81. <p>In total, HTTP Archive tracks 4,308,655 desktop URLs, and 5,484,239 mobile URLs. Among the many data points HTTP Archive reports for those URLs is a list of the detected technologies for a given site. That means we can pick out the thousands of sites that use various frameworks and see how much code they’re shipping, and what that costs the CPU.</p>
  82. <p>I ran all the queries against March of 2020, the most recent run at the time.</p>
  83. <p>I decided to compare the aggregate HTTP Archive data for all sites recorded against sites with React, Vue.js, and Angular detected.</p>
  84. <p>For fun, I also added jQuery—it’s still massively popular, and it also represents a bit of a different approach to building with JavaScript than the single-page application (<abbr title="Single-Page Application">SPA</abbr>) approach provided by React, Vue.js and Angular.</p>
  85. <table cellspacing="3" class="plain">
  86. <caption>URLs in HTTP Archive with specific frameworks detected</caption>
  87. <thead>
  88. <tr>
  89. <th>Framework</th>
  90. <th class="num">Mobile URLs</th>
  91. <th class="num">Desktop URLs</th>
  92. </tr>
  93. </thead>
  94. <tbody>
  95. <tr>
  96. <td data-title="Framework">jQuery</td>
  97. <td data-title="Mobile URLs" class="num">4,615,474</td>
  98. <td data-title="Desktop URLs" class="num">3,714,643</td>
  99. </tr>
  100. <tr>
  101. <td data-title="Framework">React</td>
  102. <td data-title="Mobile URLs" class="num">489,827</td>
  103. <td data-title="Desktop URLs" class="num">241,023</td>
  104. </tr>
  105. <tr>
  106. <td data-title="Framework">Vue.js</td>
  107. <td data-title="Mobile URLs" class="num">85,649</td>
  108. <td data-title="Desktop URLs" class="num">43,691</td>
  109. </tr>
  110. <tr>
  111. <td data-title="Framework">Angular</td>
  112. <td data-title="Mobile URLs" class="num">19,423</td>
  113. <td data-title="Desktop URLs" class="num">18,088</td>
  114. </tr>
  115. </tbody>
  116. </table>
  117. <h2 id="hopes-and-dreams">Hopes and dreams</h2>
  118. <p>Before we dig in, here’s what I would hope.</p>
  119. <p>In an ideal world, I believe a framework should go beyond developer experience value and provide concrete value for the people using our sites. Performance is just one part of that—accessibility and security both come to mind as well—but it’s an essential part.</p>
  120. <p>So in an ideal world, a framework makes it easier to perform well by either providing a better starting point or providing constraints and characteristics that make it hard to build something that doesn’t perform well.</p>
  121. <p>The best of frameworks would do both: provide a better starting point and help to restrict how out of hands things can get.</p>
  122. <p>Looking at the median for our data isn’t going to tell us that, and <a href="https://timkadlec.com/remembers/2018-06-07-prioritizing-the-long-tail-of-performance/">in fact leaves a ton of information out</a>. Instead, for each stat, I pulled the following percentiles: the 10th, 25th, 50th (the median), 75th, and 90th.</p>
  123. <p>The 10th and 90th percentiles are particularly interesting to me. The 10th percentile represents the best of class (or at least, reasonably close to the best of class) for a given framework. In other words, only 10% of all sites using a given framework reach that mark or better. The 90th percentile, on the other hand, is the opposite of the spectrum—it shows us how bad things can get. The 90th percentile represents the long-tail—that last 10% of sites with the highest number of bytes or largest amount of main thread time.</p>
  124. <h2 id="javascript-bytes">JavaScript Bytes</h2>
  125. <p>For the starting point, it makes sense to look at the amount of JavaScript passed over the network.</p>
  126. <table cellspacing="3" class="plain">
  127. <caption>JavaScript Bytes Served to Mobile Devices, by Percentile</caption>
  128. <thead>
  129. <tr>
  130. <th/>
  131. <th class="num">10th</th>
  132. <th class="num">25th</th>
  133. <th class="num">50th</th>
  134. <th class="num">75th</th>
  135. <th class="num">90th</th>
  136. </tr>
  137. </thead>
  138. <tbody>
  139. <tr>
  140. <td data-title="Dataset">All Sites</td>
  141. <td data-title="Bytes Served, 10th Percentile" class="num">93.4kb</td>
  142. <td data-title="Bytes Served, 25th Percentile" class="num">196.6kb</td>
  143. <td data-title="Bytes Served, 50th Percentile" class="num">413.5kb</td>
  144. <td data-title="Bytes Served, 75th Percentile" class="num">746.8kb</td>
  145. <td data-title="Bytes Served, 90th Percentile" class="num">1,201.6kb</td>
  146. </tr>
  147. <tr>
  148. <td data-title="Dataset">Sites with jQuery</td>
  149. <td data-title="Bytes Served, 10th Percentile" class="num">110.3kb</td>
  150. <td data-title="Bytes Served, 25th Percentile" class="num">219.8kb</td>
  151. <td data-title="Bytes Served, 50th Percentile" class="num">430.4kb</td>
  152. <td data-title="Bytes Served, 75th Percentile" class="num">748.6kb</td>
  153. <td data-title="Bytes Served, 90th Percentile" class="num">1,162.3kb</td>
  154. </tr>
  155. <tr>
  156. <td data-title="Dataset">Sites with Vue.js</td>
  157. <td data-title="Bytes Served, 10th Percentile" class="num">244.7kb</td>
  158. <td data-title="Bytes Served, 25th Percentile" class="num">409.3kb</td>
  159. <td data-title="Bytes Served, 50th Percentile" class="num">692.1kb</td>
  160. <td data-title="Bytes Served, 75th Percentile" class="num">1,065.5kb</td>
  161. <td data-title="Bytes Served, 90th Percentile" class="num">1,570.7kb</td>
  162. </tr>
  163. <tr>
  164. <td data-title="Dataset">Sites with Angular</td>
  165. <td data-title="Bytes Served, 10th Percentile" class="num">445.1kb</td>
  166. <td data-title="Bytes Served, 25th Percentile" class="num">675.6kb</td>
  167. <td data-title="Bytes Served, 50th Percentile" class="num">1,066.4kb</td>
  168. <td data-title="Bytes Served, 75th Percentile" class="num">1,761.5kb</td>
  169. <td data-title="Bytes Served, 90th Percentile" class="num">2,893.2kb</td>
  170. </tr>
  171. <tr>
  172. <td data-title="Dataset">Sites with React</td>
  173. <td data-title="Bytes Served, 10th Percentile" class="num">345.8kb</td>
  174. <td data-title="Bytes Served, 25th Percentile" class="num">441.6kb</td>
  175. <td data-title="Bytes Served, 50th Percentile" class="num">690.3kb</td>
  176. <td data-title="Bytes Served, 75th Percentile" class="num">1,238.5kb</td>
  177. <td data-title="Bytes Served, 90th Percentile" class="num">1,893.6kb</td>
  178. </tr>
  179. </tbody>
  180. </table>
  181. <p><picture class="diagram">
  182. <source media="(min-width: 650px)" srcset="/images/cost-of-frameworks-bytes-mobile.png">
  183. <img src="/images/cost-of-frameworks-bytes-mobile-sm.png" alt="Boxplot charts showing the amount of JavaScript bytes served to mobile devices for sites with various frameworks. Also presented by the preceding table"/>
  184. </source></picture></p>
  185. <table cellspacing="3" class="plain">
  186. <caption>JavaScript Bytes Served to Desktop Devices, by Percentile</caption>
  187. <thead>
  188. <tr>
  189. <th/>
  190. <th class="num">10th</th>
  191. <th class="num">25th</th>
  192. <th class="num">50th</th>
  193. <th class="num">75th</th>
  194. <th class="num">90th</th>
  195. </tr>
  196. </thead>
  197. <tbody>
  198. <tr>
  199. <td data-title="Dataset">All Sites</td>
  200. <td data-title="Bytes Served, 10th Percentile" class="num">105.5kb</td>
  201. <td data-title="Bytes Served, 25th Percentile" class="num">226.6kb</td>
  202. <td data-title="Bytes Served, 50th Percentile" class="num">450.4kb</td>
  203. <td data-title="Bytes Served, 75th Percentile" class="num">808.8kb</td>
  204. <td data-title="Bytes Served, 90th Percentile" class="num">1,267.3kb</td>
  205. </tr>
  206. <tr>
  207. <td data-title="Dataset">Sites with jQuery</td>
  208. <td data-title="Bytes Served, 10th Percentile" class="num">121.7kb</td>
  209. <td data-title="Bytes Served, 25th Percentile" class="num">242.2kb</td>
  210. <td data-title="Bytes Served, 50th Percentile" class="num">458.3kb</td>
  211. <td data-title="Bytes Served, 75th Percentile" class="num">803.4kb</td>
  212. <td data-title="Bytes Served, 90th Percentile" class="num">1,235.3kb</td>
  213. </tr>
  214. <tr>
  215. <td data-title="Dataset">Sites with Vue.js</td>
  216. <td data-title="Bytes Served, 10th Percentile" class="num">248.0kb</td>
  217. <td data-title="Bytes Served, 25th Percentile" class="num">420.1kb</td>
  218. <td data-title="Bytes Served, 50th Percentile" class="num">718.0kb</td>
  219. <td data-title="Bytes Served, 75th Percentile" class="num">1,122.5kb</td>
  220. <td data-title="Bytes Served, 90th Percentile" class="num">1,643.1kb</td>
  221. </tr>
  222. <tr>
  223. <td data-title="Dataset">Sites with Angular</td>
  224. <td data-title="Bytes Served, 10th Percentile" class="num">468.8kb</td>
  225. <td data-title="Bytes Served, 25th Percentile" class="num">716.9kb</td>
  226. <td data-title="Bytes Served, 50th Percentile" class="num">1,144.2kb</td>
  227. <td data-title="Bytes Served, 75th Percentile" class="num">1,930.0kb</td>
  228. <td data-title="Bytes Served, 90th Percentile" class="num">3,283.1kb</td>
  229. </tr>
  230. <tr>
  231. <td data-title="Dataset">Sites with React</td>
  232. <td data-title="Bytes Served, 10th Percentile" class="num">308.6kb</td>
  233. <td data-title="Bytes Served, 25th Percentile" class="num">469.0kb</td>
  234. <td data-title="Bytes Served, 50th Percentile" class="num">841.9kb</td>
  235. <td data-title="Bytes Served, 75th Percentile" class="num">1,472.2kb</td>
  236. <td data-title="Bytes Served, 90th Percentile" class="num">2,197.8kb</td>
  237. </tr>
  238. </tbody>
  239. </table>
  240. <p><picture class="diagram">
  241. <source media="(min-width: 650px)" srcset="/images/cost-of-frameworks-bytes-desktop.png">
  242. <img src="/images/cost-of-frameworks-bytes-desktop-sm.png" alt="Boxplot charts showing the amount of JavaScript bytes served to desktop devices for sites with various frameworks. Also presented by the preceding table"/>
  243. </source></picture></p>
  244. <p>For the sheer payload size, the 10th percentile turns out pretty much as you would expect: if one of these frameworks are in use, there’s more JavaScript even in the most ideal of situations. That’s not surprising—you can’t add a JavaScript framework as a default starting point and expect to ship less JavaScript out of the box.</p>
  245. <p>What <em>is</em> notable is that some frameworks correlate to better starting points than others. Sites with jQuery are the best of the bunch, starting with about 15% more JavaScript on desktop devices and about 18% more on mobile. (There’s admittedly a little bit of bias here. jQuery is found on a lot of sites, so naturally, it’s going to have a tighter relationship to the overall numbers than others. Still, that doesn’t change the way the raw numbers appear for each framework.)</p>
  246. <p>While even a 15-18% increase is notable, comparing that to the opposite end of the spectrum makes the jQuery tax feel very low. Sites with Angular ship 344% more JavaScript on desktop at the 10th percentile, and 377% more on mobile. Sites with React, the next heaviest, ship 193% more JavaScript on desktop and 270% more on mobile devices.</p>
  247. <p>I mentioned earlier that even if the starting point is a little off, I would hope that a framework could still provide value by limiting the upper bound in some way.</p>
  248. <p>Interestingly, jQuery driven sites follow this pattern. While they’re a bit heftier (15-18%) at the 10th percentile, they’re slightly smaller than the aggregate at the 90th percentile—about 3% on both desktop and mobile. Neither of those numbers is super significant, but at least sites with jQuery don’t seem to have a dramatically worse long-tail in terms of JavaScript bytes shipped.</p>
  249. <p>The same can’t be said of the other frameworks.</p>
  250. <p>Just as with the 10th percentile, Angular and React driven sites tend to distance themselves from others at the 90th percentile, and not in a very flattering way.</p>
  251. <p>At the 90th percentile, Angular sites ship 141% more bytes on mobile and 159% more bytes on desktop. Sites with React ship 73% more bytes on desktop and 58% more on mobile. With a 90th percentile weight of 2,197.8kb, React sites ship 322.9kb more bytes of JavaScript to mobile users than Vue.js, the next closest. The desktop gap between Angular and React and the rest of the crowd is even higher—React-driven sites ship 554.7kb more JavaScript than Vue.js-driven sites.</p>
  252. <h2 id="javascript-main-thread-time">JavaScript Main Thread Time</h2>
  253. <p>It’s clear from the data that sites with these frameworks in place tend to pay a large penalty in terms of bytes. But of course, that’s just one part of the equation.</p>
  254. <p>Once that JavaScript arrives, it has to get to work. Any work that occurs on the main thread of the browser is particularly troubling. The main thread is responsible for handling user input, during style calculation, layout and painting. If we’re clogging it up with a lot of JavaScript work, the main thread has no chance to do those things in a timely manner, leading to lag and jank.</p>
  255. <p>HTTP Archive records V8 main thread time, so we can query to see just how much time that main thread is working on all that JavaScript.</p>
  256. <table cellspacing="3" class="plain">
  257. <caption>Scripting related CPU time (in milliseconds) for mobile devices, in percentiles</caption>
  258. <thead>
  259. <tr>
  260. <th/>
  261. <th class="num">10th</th>
  262. <th class="num">25th</th>
  263. <th class="num">50th</th>
  264. <th class="num">75th</th>
  265. <th class="num">90th</th>
  266. </tr>
  267. </thead>
  268. <tbody>
  269. <tr>
  270. <td data-title="Dataset">All Sites</td>
  271. <td data-title="Main thread time, 10th Percentile" class="num">356.4ms</td>
  272. <td data-title="Main thread time, 25th Percentile" class="num">959.7ms</td>
  273. <td data-title="Main thread time, 50th Percentile" class="num">2,372.1ms</td>
  274. <td data-title="Main thread time, 75th Percentile" class="num">5,367.3ms</td>
  275. <td data-title="Main thread time, 90th Percentile" class="num">10,485.8ms</td>
  276. </tr>
  277. <tr>
  278. <td data-title="Dataset">Sites with jQuery</td>
  279. <td data-title="Main thread time, 10th Percentile" class="num">575.3ms</td>
  280. <td data-title="Main thread time, 25th Percentile" class="num">1,147.4ms</td>
  281. <td data-title="Main thread time, 50th Percentile" class="num">2,555.9ms</td>
  282. <td data-title="Main thread time, 75th Percentile" class="num">5,511.0ms</td>
  283. <td data-title="Main thread time, 90th Percentile" class="num">10,349.4ms</td>
  284. </tr>
  285. <tr>
  286. <td data-title="Dataset">Sites with Vue.js</td>
  287. <td data-title="Main thread time" class="num">1,130.0ms</td>
  288. <td data-title="Main thread time" class="num">2,087.9ms</td>
  289. <td data-title="Main thread time" class="num">4,100.4ms</td>
  290. <td data-title="Main thread time" class="num">7,676.1ms</td>
  291. <td data-title="Main thread time" class="num">12,849.4ms</td>
  292. </tr>
  293. <tr>
  294. <td data-title="Dataset">Sites with Angular</td>
  295. <td data-title="Main thread time, 10th Percentile" class="num">1,471.3ms</td>
  296. <td data-title="Main thread time, 25th Percentile" class="num">2,380.1ms</td>
  297. <td data-title="Main thread time, 50th Percentile" class="num">4,118.6ms</td>
  298. <td data-title="Main thread time, 75th Percentile" class="num">7,450.8ms</td>
  299. <td data-title="Main thread time, 90th Percentile" class="num">13,296.4ms</td>
  300. </tr>
  301. <tr>
  302. <td data-title="Dataset">Sites with React</td>
  303. <td data-title="Main thread time, 10th Percentile" class="num">2,700.1ms</td>
  304. <td data-title="Main thread time, 25th Percentile" class="num">5,090.3ms</td>
  305. <td data-title="Main thread time, 50th Percentile" class="num">9,287.6ms</td>
  306. <td data-title="Main thread time, 75th Percentile" class="num">14,509.6ms</td>
  307. <td data-title="Main thread time, 90th Percentile" class="num">20,813.3ms</td>
  308. </tr>
  309. </tbody>
  310. </table>
  311. <p><picture class="diagram">
  312. <source media="(min-width: 650px)" srcset="/images/cost-of-frameworks-cpu-mobile.png">
  313. <img src="/images/cost-of-frameworks-cpu-mobile-sm.png" alt="Boxplot charts showing the amount of JavaScript cpu time for mobile tests for sites with various frameworks. Also presented by the preceding table"/>
  314. </source></picture></p>
  315. <table cellspacing="3" class="plain">
  316. <caption>Scripting related CPU time (in milliseconds) for desktop devices, in percentiles</caption>
  317. <thead>
  318. <tr>
  319. <th/>
  320. <th data-title="Main thread time, 10th Percentile" class="num">10th</th>
  321. <th data-title="Main thread time, 25th Percentile" class="num">25th</th>
  322. <th data-title="Main thread time, 50th Percentile" class="num">50th</th>
  323. <th data-title="Main thread time, 75th Percentile" class="num">75th</th>
  324. <th data-title="Main thread time, 90th Percentile" class="num">90th</th>
  325. </tr>
  326. </thead>
  327. <tbody>
  328. <tr>
  329. <td data-title="Dataset">All Sites</td>
  330. <td data-title="Main thread time" class="num">146.0ms</td>
  331. <td data-title="Main thread time" class="num">351.8ms</td>
  332. <td data-title="Main thread time" class="num">831.0ms</td>
  333. <td data-title="Main thread time" class="num">1,739.8ms</td>
  334. <td data-title="Main thread time" class="num">3,236.8ms</td>
  335. </tr>
  336. <tr>
  337. <td data-title="Dataset">Sites with jQuery</td>
  338. <td data-title="Main thread time, 10th Percentile" class="num">199.6ms</td>
  339. <td data-title="Main thread time, 25th Percentile" class="num">399.2ms</td>
  340. <td data-title="Main thread time, 50th Percentile" class="num">877.5ms</td>
  341. <td data-title="Main thread time, 75th Percentile" class="num">1,779.9ms</td>
  342. <td data-title="Main thread time, 90th Percentile" class="num">3,215.5ms</td>
  343. </tr>
  344. <tr>
  345. <td data-title="Dataset">Sites with Vue.js</td>
  346. <td data-title="Main thread time, 10th Percentile" class="num">350.4ms</td>
  347. <td data-title="Main thread time, 25th Percentile" class="num">650.8ms</td>
  348. <td data-title="Main thread time, 50th Percentile" class="num">1,280.7ms</td>
  349. <td data-title="Main thread time, 75th Percentile" class="num">2,388.5ms</td>
  350. <td data-title="Main thread time, 90th Percentile" class="num">4,010.8ms</td>
  351. </tr>
  352. <tr>
  353. <td data-title="Dataset">Sites with Angular</td>
  354. <td data-title="Main thread time, 10th Percentile" class="num">482.2ms</td>
  355. <td data-title="Main thread time, 25th Percentile" class="num">777.9ms</td>
  356. <td data-title="Main thread time, 50th Percentile" class="num">1,365.5ms</td>
  357. <td data-title="Main thread time, 75th Percentile" class="num">2,400.6ms</td>
  358. <td data-title="Main thread time, 90th Percentile" class="num">4,171.8ms</td>
  359. </tr>
  360. <tr>
  361. <td data-title="Dataset">Sites with React</td>
  362. <td data-title="Main thread time, 10th Percentile" class="num">508.0ms</td>
  363. <td data-title="Main thread time, 25th Percentile" class="num">1,045.6ms</td>
  364. <td data-title="Main thread time, 50th Percentile" class="num">2,121.1ms</td>
  365. <td data-title="Main thread time, 75th Percentile" class="num">4,235.1ms</td>
  366. <td data-title="Main thread time, 90th Percentile" class="num">7,444.3ms</td>
  367. </tr>
  368. </tbody>
  369. </table>
  370. <p><picture class="diagram">
  371. <source media="(min-width: 650px)" srcset="/images/cost-of-frameworks-cpu-desktop.png">
  372. <img src="/images/cost-of-frameworks-cpu-desktop-sm.png" alt="Boxplot charts showing the amount of JavaScript cpu time for desktop tests for sites with various frameworks. Also presented by the preceding table"/>
  373. </source></picture></p>
  374. <p>There are some very familiar themes here.</p>
  375. <p>First, sites with jQuery detected spend <em>much</em> less time on JavaScript work on the main thread than the other three analyzed. At the 10th percentile, there’s a 61% increase in JavaScript main thread work being done on mobile devices and 37% more on desktop. At the 90th percentile, jQuery sites are gain pretty darn close to the aggregate, spending 1.3% <em>less</em> time on the main thread for mobile devices and ..7% less time on desktop machines.</p>
  376. <p>The opposite end—the frameworks that correlate to the most time spent on the main thread—is once again made up of Angular and React. The only difference is that while Angular sites shipped more JavaScript than React sites, they actually spend less time on the CPU—<em>much</em> less time.</p>
  377. <p>At the 10th percentile, Angular sites spend 230% more time on the CPU for JavaScript related work on desktop devices, and 313% more on mobile devices. React sites bring up the tail end, spending 248% more time on desktop devices and 658% more time on mobile devices. No, 658% is not a typo. At the 10th percentile, sites with React spend 2.7s on the main thread dealing with all the JavaScript sent down.</p>
  378. <p>Compared to those big numbers, the situation at the 90th percentile at least looks a little better. The main thread of Angular sites spends 29% more time on JavaScript for desktop devices and 27% more time on mobile devices. React sites spend 130% more time on desktop and 98% more time on mobile devices.</p>
  379. <p>Those percentages look much better than at the 10th percentile, but keep in mind that the bulk numbers are pretty scary: that’s 20.8s of main thread work for sites built with React at the 90th percentile on mobile devices. (What, exactly, is happening during that time is a topic for a follow-up post, I think.)</p>
  380. <p>There’s one potential gotcha (thanks <a href="https://jeremy.codes/">Jeremy</a> for making sure I double-checked the stats from this angle)—many sites will pull in multiple libraries. In particular, I see a lot of sites pulling jQuery in alongside React or Vue.js as they’re migrating to that architecture. So, I re-ran the queries, only this time I only included URLs that included only React, jQuery, Angular or Vue.js <em>not some combination of them</em>.</p>
  381. <table cellspacing="3" class="plain">
  382. <caption>Scripting related CPU time (in milliseconds) for mobile devices where only one of the frameworks is detected, in percentiles</caption>
  383. <thead>
  384. <tr>
  385. <th/>
  386. <th class="num">10th</th>
  387. <th class="num">25th</th>
  388. <th class="num">50th</th>
  389. <th class="num">75th</th>
  390. <th class="num">90th</th>
  391. </tr>
  392. </thead>
  393. <tbody>
  394. <tr>
  395. <td data-title="Dataset">Sites with only jQuery</td>
  396. <td data-title="Main thread time, 10th Percentile" class="num">542.9ms</td>
  397. <td data-title="Main thread time, 25th Percentile" class="num">1,062.2ms</td>
  398. <td data-title="Main thread time, 50th Percentile" class="num">2,297.4ms</td>
  399. <td data-title="Main thread time, 75th Percentile" class="num">4,769.7ms</td>
  400. <td data-title="Main thread time, 90th Percentile" class="num">8,718.2ms</td>
  401. </tr>
  402. <tr>
  403. <td data-title="Dataset">Sites with only Vue.js</td>
  404. <td data-title="Main thread time, 10th Percentile" class="num">944.0ms</td>
  405. <td data-title="Main thread time, 25th Percentile" class="num">1,716.3ms</td>
  406. <td data-title="Main thread time, 50th Percentile" class="num">3,194.7ms</td>
  407. <td data-title="Main thread time, 75th Percentile" class="num">5,959.6ms</td>
  408. <td data-title="Main thread time, 90th Percentile" class="num">9,843.8ms</td>
  409. </tr>
  410. <tr>
  411. <td data-title="Dataset">Sites with Angular</td>
  412. <td data-title="Main thread time, 10th Percentile" class="num">1,328.9ms</td>
  413. <td data-title="Main thread time, 25th Percentile" class="num">2,151.9ms</td>
  414. <td data-title="Main thread time, 50th Percentile" class="num">3,695.3ms</td>
  415. <td data-title="Main thread time, 75th Percentile" class="num">6,629.3ms</td>
  416. <td data-title="Main thread time, 90th Percentile" class="num">11,607.7ms</td>
  417. </tr>
  418. <tr>
  419. <td data-title="Dataset">Sites with React</td>
  420. <td data-title="Main thread time, 10th Percentile" class="num">2,443.2ms</td>
  421. <td data-title="Main thread time, 25th Percentile" class="num">4,620.5ms</td>
  422. <td data-title="Main thread time, 50th Percentile" class="num">10,061.4ms</td>
  423. <td data-title="Main thread time, 75th Percentile" class="num">17,074.3ms</td>
  424. <td data-title="Main thread time, 90th Percentile" class="num">24,956.3ms</td>
  425. </tr>
  426. </tbody>
  427. </table>
  428. <p><picture class="diagram">
  429. <source media="(min-width: 650px)" srcset="/images/cost-of-frameworks-cpu-mobile-only.png">
  430. <img src="/images/cost-of-frameworks-cpu-mobile-only-sm.png" alt="Boxplot charts showing the amount of JavaScript cpu time for mobiles tests for sites with only one framework detected. Also presented by the preceding table"/>
  431. </source></picture></p>
  432. <p>First, the unsurprising bit: when only one framework is used, performance improves far more often than not. The numbers for every framework look better at the 10th and 25th percentile. That makes sense. A site that is built well with one framework <em>should</em> perform better than a site that is built well with two or more.</p>
  433. <p>In fact, the numbers for every framework look better at each percentile with one curious exception.
  434. What surprised me, and the reason I ended up including this data, is that at the 50th percentile and beyond, sites using React perform <em>worse</em> when React is the only framework in use.</p>
  435. <p>It’s a bit odd, but here’s my best guess.</p>
  436. <p>If you have React and jQuery running alongside each other, you’re more likely to be in the midst of a migration to React, or a mixed codebase. Since we have already seen that sites with jQuery spend less time on the main thread than sites with React, it makes sense that having some functionality still driven by jQuery would bring the numbers down a bit.</p>
  437. <p>As you move away from jQuery and focus more on React exclusively, though, that changes. If the site is built really well and you’re using React sparingly, you’re fine. But for the average site, more work inside of React means the main thread receives an increasing amount of strain.</p>
  438. <h2 id="the-mobile-desktop-gap">The mobile/desktop gap</h2>
  439. <p>Another angle that’s worth looking at is just how large the gap is between that mobile experience and the desktop experience. Looking at it from a bytes perspective, nothing too scary jumps out. Sure, I’d love to see fewer bytes passed along, but neither mobile nor desktop devices receive significantly more bytes than the other.</p>
  440. <p>But once you look at the processing time, the gap is significant.</p>
  441. <table cellspacing="3" class="plain">
  442. <caption>Percentage increase in main thread scripting work on mobile devices compared to desktop devices, by percentiles</caption>
  443. <thead>
  444. <tr>
  445. <th/>
  446. <th class="num">10th</th>
  447. <th class="num">25th</th>
  448. <th class="num">50th</th>
  449. <th class="num">75th</th>
  450. <th class="num">90th</th>
  451. </tr>
  452. </thead>
  453. <tbody>
  454. <tr>
  455. <td data-title="Dataset">All Sites</td>
  456. <td data-title="Change from Desktop to Mobile, 10th percentile" class="num">144.1%</td>
  457. <td data-title="Change from Desktop to Mobile, 25th percentile" class="num">172.8%</td>
  458. <td data-title="Change from Desktop to Mobile, 50th percentile" class="num">185.5%</td>
  459. <td data-title="Change from Desktop to Mobile, 75th percentile" class="num">208.5%</td>
  460. <td data-title="Change from Desktop to Mobile, 90th percentile" class="num">224.0%</td>
  461. </tr>
  462. <tr>
  463. <td data-title="Dataset">Sites with jQuery</td>
  464. <td data-title="Change from Desktop to Mobile, 10th percentile" class="num">188.2%</td>
  465. <td data-title="Change from Desktop to Mobile, 25th percentile" class="num">187.4%</td>
  466. <td data-title="Change from Desktop to Mobile, 50th percentile" class="num">191.3%</td>
  467. <td data-title="Change from Desktop to Mobile, 75th percentile" class="num">209.6%</td>
  468. <td data-title="Change from Desktop to Mobile, 90th percentile" class="num">221.9%</td>
  469. </tr>
  470. <tr>
  471. <td data-title="Dataset">Sites with Vue.js</td>
  472. <td data-title="Change from Desktop to Mobile, 10th percentile" class="num">222.5%</td>
  473. <td data-title="Change from Desktop to Mobile, 25th percentile" class="num">220.8%</td>
  474. <td data-title="Change from Desktop to Mobile, 50th percentile" class="num">220.2%</td>
  475. <td data-title="Change from Desktop to Mobile, 75th percentile" class="num">221.4%</td>
  476. <td data-title="Change from Desktop to Mobile, 90th percentile" class="num">220.4%</td>
  477. </tr>
  478. <tr>
  479. <td data-title="Dataset">Sites with Angular</td>
  480. <td data-title="Change from Desktop to Mobile, 10th percentile" class="num">205.1%</td>
  481. <td data-title="Change from Desktop to Mobile, 25th percentile" class="num">206.0%</td>
  482. <td data-title="Change from Desktop to Mobile, 50th percentile" class="num">201.6%</td>
  483. <td data-title="Change from Desktop to Mobile, 75th percentile" class="num">210.4%</td>
  484. <td data-title="Change from Desktop to Mobile, 90th percentile" class="num">218.7%</td>
  485. </tr>
  486. <tr>
  487. <td data-title="Dataset">Sites with React</td>
  488. <td data-title="Change from Desktop to Mobile, 10th percentile" class="num">431.5%</td>
  489. <td data-title="Change from Desktop to Mobile, 25th percentile" class="num">386.8%</td>
  490. <td data-title="Change from Desktop to Mobile, 50th percentile" class="num">337.9%</td>
  491. <td data-title="Change from Desktop to Mobile, 75th percentile" class="num">242.6%</td>
  492. <td data-title="Change from Desktop to Mobile, 90th percentile" class="num">179.6%</td>
  493. </tr>
  494. </tbody>
  495. </table>
  496. <p>While some variance is expected between a phone and a laptop, seeing numbers this high tells me that the current crop of frameworks isn’t doing enough to prioritize less powerful devices and help to close that gap. Even at the 10th percentile, React sites spend 431.5% more time on the main thread on mobile devices as they do on desktop devices. jQuery has the lowest gap of all frameworks, but even there, it equates to 188.2% more time on mobile devices. When we make the CPU work harder—and increasingly we are—folks with less powerful devices end up holding the bill.</p>
  497. <h2 id="the-big-picture">The big picture</h2>
  498. <p>Good frameworks should provide a better starting point on the essentials (security, accessibility, performance) or have built-in constraints that make it harder to ship something that violates those.</p>
  499. <p>That doesn’t appear to be happening with performance (<a href="https://webaim.org/projects/million/#frameworks">nor with accessibility</a>, apparently).</p>
  500. <p>It’s worth noting that because sites with React or Angular spend more time on the CPU than others, that isn’t necessarily the same as saying React is more expensive on the CPU than Vue.js. In fact, it says very little about the performance of the core frameworks in play and much more about the approach to development these frameworks may encourage (whether intentionally or not) through documentation, ecosystem, and general coding practices.</p>
  501. <p>It’s also worth noting what we don’t have here: data about how much time the device spends on this JavaScript for subsequent views. The argument for the <abbr title="Single-Page Application">SPA</abbr> architecture is that, once the <abbr title="Single-Page Application">SPA</abbr> is in place, you theoretically get faster subsequent page loads. My own experience tells me that’s far from a given, but we don’t have concrete data here to make that case in either direction.</p>
  502. <p>What is clear: right now, if you’re using a framework to build your site, you’re making a trade-off in terms of initial performance—even in the best of scenarios.</p>
  503. <p><em>Some</em> trade-off may be acceptable in the right situations, but it’s important that we make that exchange consciously.</p>
  504. <p>There’s reason for optimism. I’m encouraged by how closely the folks at Chrome have been working with some of these frameworks to help improve their performance.</p>
  505. <p>But I’m also pragmatic. New architectures tend to create performance problems just as often as they solve them, and it takes time to right the ship. Just as <a href="https://timkadlec.com/remembers/2019-04-18-new-network-fallacies/">we shouldn’t expect new networks to solve all our performance woes</a>, we shouldn’t expect that the next version of our favorite framework is going to solve them all either.</p>
  506. <p>If you are going to use one of these frameworks, then you have to take extra steps to make sure you don’t negatively impact performance in the meantime. Here are a few great starting considerations:</p>
  507. <ul>
  508. <li>Do a sanity check: do you <em>really</em> need to use it? Vanilla JavaScript can do <em>a lot</em> today.</li>
  509. <li>Is there a lighter alternative (Preact, Svelte, etc.) that gets you 90% of the way there?</li>
  510. <li>If you’re going with a framework, does anything exist that provides better, more opinionated defaults (ex: Nuxt.js instead of Vue.js, Next.js instead of React, etc.)?</li>
  511. <li>What’s your <a href="https://timkadlec.com/remembers/2019-03-07-performance-budgets-that-stick/">performance budget going to be</a> for your JavaScript?</li>
  512. <li>What friction can you introduce into the workflow that makes it harder to <a href="https://timkadlec.com/remembers/2020-03-18-building-with-friction/">add any more JavaScript than absolutely necessary</a>?</li>
  513. <li>If you’re using a framework for the developer ergonomics, do you <a href="https://www.gatsbyjs.org/packages/gatsby-plugin-no-javascript/">need to ship it down to the client</a>, or can you handle that all on the server?</li>
  514. </ul>
  515. <p>These are generally good things to consider regardless of your technology choice, but they’re particularly important if you’re starting with a performance deficit from the beginning.</p>
  516. <p>For example, we could use all sites that didn't have any of the mentioned frameworks (jQuery, React, Vue.js, Angular) detected.</p>
  517. <p> Here are the numbers for the JavaScript main thread work on mobile devices for those URLs:
  518. </p>
  519. <table cellspacing="3" class="plain">
  520. <caption>Scripting related CPU time (in milliseconds) for mobile devices, in percentiles</caption>
  521. <thead>
  522. <tr>
  523. <th/>
  524. <th class="num">10th</th>
  525. <th class="num">25th</th>
  526. <th class="num">50th</th>
  527. <th class="num">75th</th>
  528. <th class="num">90th</th>
  529. </tr>
  530. </thead>
  531. <tbody>
  532. <tr>
  533. <td data-title="Dataset">All Sites</td>
  534. <td data-title="Main thread time, 10th Percentile" class="num">6.3ms</td>
  535. <td data-title="Main thread time, 25th Percentile" class="num">75.3ms</td>
  536. <td data-title="Main thread time, 50th Percentile" class="num">382.2ms</td>
  537. <td data-title="Main thread time, 75th Percentile" class="num">2,316.6ms</td>
  538. <td data-title="Main thread time, 90th Percentile" class="num">5,504.7ms</td>
  539. </tr>
  540. </tbody>
  541. </table>
  542. <p>Going even further, we could use all sites with no JavaScript framework or library detected at all. Here's what the main thread time looks like for those:</p>
  543. <table cellspacing="3" class="plain">
  544. <caption>Scripting related CPU time (in milliseconds) for mobile devices, in percentiles</caption>
  545. <thead>
  546. <tr>
  547. <th/>
  548. <th class="num">10th</th>
  549. <th class="num">25th</th>
  550. <th class="num">50th</th>
  551. <th class="num">75th</th>
  552. <th class="num">90th</th>
  553. </tr>
  554. </thead>
  555. <tbody>
  556. <tr>
  557. <td data-title="Dataset">All Sites</td>
  558. <td data-title="Main thread time, 10th Percentile" class="num">3.6ms</td>
  559. <td data-title="Main thread time, 25th Percentile" class="num">29.9ms</td>
  560. <td data-title="Main thread time, 50th Percentile" class="num">193.2ms</td>
  561. <td data-title="Main thread time, 75th Percentile" class="num">1,399.6ms</td>
  562. <td data-title="Main thread time, 90th Percentile" class="num">3,714.5ms</td>
  563. </tr>
  564. </tbody>
  565. </table>
  566. <p>With either baseline, the data would have looked less favorable and more dramatic. Ultimately, I ended up using the aggregate data as the baseline because:</p>
  567. <ul>
  568. <li>It's what is used broadly in the community whenever this stuff is discussed.</li>
  569. <li>It avoids derailing the conversation with debates about whether or not sites without frameworks are complex enough to be an accurate comparison. You can build large, complex sites without using a framework—I've worked with companies who have—but it's an argument that would distract from the otherwise pretty clear conclusions from the data.</li>
  570. </ul>
  571. <p>Still, as a few folks pointed out to me when I was showing them the data, it's interesting to see these alternate baselines as they do make it very clear how much these tools are messing with the averages.</p>
  572. </div>
  573. </main>
  574. </article>
  575. <hr>
  576. <footer>
  577. <p>
  578. <a href="/david/" title="Aller à l’accueil">🏠</a> •
  579. <a href="/david/log/" title="Accès au flux RSS">🤖</a> •
  580. <a href="http://larlet.com" title="Go to my English profile" data-instant>🇨🇦</a> •
  581. <a href="mailto:david%40larlet.fr" title="Envoyer un courriel">📮</a> •
  582. <abbr title="Hébergeur : Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33184162340">🧚</abbr>
  583. </p>
  584. <template id="theme-selector">
  585. <form>
  586. <fieldset>
  587. <legend>Thème</legend>
  588. <label>
  589. <input type="radio" value="auto" name="chosen-color-scheme" checked> Auto
  590. </label>
  591. <label>
  592. <input type="radio" value="dark" name="chosen-color-scheme"> Foncé
  593. </label>
  594. <label>
  595. <input type="radio" value="light" name="chosen-color-scheme"> Clair
  596. </label>
  597. </fieldset>
  598. </form>
  599. </template>
  600. </footer>
  601. <script type="text/javascript">
  602. function loadThemeForm(templateName) {
  603. const themeSelectorTemplate = document.querySelector(templateName)
  604. const form = themeSelectorTemplate.content.firstElementChild
  605. themeSelectorTemplate.replaceWith(form)
  606. form.addEventListener('change', (e) => {
  607. const chosenColorScheme = e.target.value
  608. localStorage.setItem('theme', chosenColorScheme)
  609. toggleTheme(chosenColorScheme)
  610. })
  611. const selectedTheme = localStorage.getItem('theme')
  612. if (selectedTheme && selectedTheme !== 'undefined') {
  613. form.querySelector(`[value="${selectedTheme}"]`).checked = true
  614. }
  615. }
  616. const prefersColorSchemeDark = '(prefers-color-scheme: dark)'
  617. window.addEventListener('load', () => {
  618. let hasDarkRules = false
  619. for (const styleSheet of Array.from(document.styleSheets)) {
  620. let mediaRules = []
  621. for (const cssRule of styleSheet.cssRules) {
  622. if (cssRule.type !== CSSRule.MEDIA_RULE) {
  623. continue
  624. }
  625. // WARNING: Safari does not have/supports `conditionText`.
  626. if (cssRule.conditionText) {
  627. if (cssRule.conditionText !== prefersColorSchemeDark) {
  628. continue
  629. }
  630. } else {
  631. if (cssRule.cssText.startsWith(prefersColorSchemeDark)) {
  632. continue
  633. }
  634. }
  635. mediaRules = mediaRules.concat(Array.from(cssRule.cssRules))
  636. }
  637. // WARNING: do not try to insert a Rule to a styleSheet you are
  638. // currently iterating on, otherwise the browser will be stuck
  639. // in a infinite loop…
  640. for (const mediaRule of mediaRules) {
  641. styleSheet.insertRule(mediaRule.cssText)
  642. hasDarkRules = true
  643. }
  644. }
  645. if (hasDarkRules) {
  646. loadThemeForm('#theme-selector')
  647. }
  648. })
  649. </script>
  650. </body>
  651. </html>