📜 ⬆️ ⬇️

Price of using frameworks

Not so long ago I had the opportunity to speak at the FFConf conference with the report “You should use <write the necessary library / framework>, this is the best!”. And I decided to set out the main ideas in a publication, in the hope that this will provoke a wider discussion in the professional environment about the “cost” of modern frameworks on mobile devices.

For those who want to refer to the original of my speech here is the video:


')
and presentation slides: speakerdeck.com/paullewis/framework- here-its-the-bestestest .

Framework Benefits


At the beginning of the year I wrote about the dependence of the performance of the React framework on increasing the size of the tree with which it operates (TL; DR: the larger it is, the more computing power is used). I received a lot of feedback on this publication, varying in a very wide range - from appreciative and constructive to bright negative. Thanks to this feedback, I collected additional information, which to a greater or lesser extent can be attributed to all frameworks:

And the most important factor was the ease of use - most developers explicitly or implicitly noted it. This collective opinion can be formulated as follows: "If it will be easier for me to live, I can do something better for users." It seems to sound good. But, as it seems to me, at such a position many important points are overlooked.

Developer comfort and user needs


We must not forget that users have their own needs. In particular, such:

There is a problem: on the one hand - the convenience and comfort of developers, on the other - user needs. And since frameworks are not free in terms of resource use, all this needs to be somehow linked to each other, whether we like it or not.

Small retreat


Here I propose to exclude individual libraries from consideration. After all, if there are any problems with them, then they can be replaced by others. Don't like how the library sets the date format? Just plug in some more. But changing the framework is not so easy. Often this requires rebuilding the entire application. In addition, frameworks occupy much more space and are involved in applications much wider and deeper.

"Cost" code


Each development has its own "price". But I believe that each framework makes a unique contribution to the total “cost”.

image

That magic moment, when the framework informs you about something not recommended (unacceptable). Probably, the message gave Java. Strange.


Users also "pay" their price:

Data on the table


Given all this, I propose to discuss the measurement of some of these values. Perhaps by joint efforts we will manage to figure out how best to reach a compromise on the chosen points. I will start from the time of the initial loading of frameworks on smartphones. For testing, I chose TodoMVC. For me, this is the MVP web application, and from the user's point of view, all the options for functionality are identical.

image

Initial load


I measured the following parameters: time, bandwidth and CPU utilization. Tests were conducted on the Nexus 5 and iPhone 5S.

image

I decided to measure how long each framework takes:

I ignored the cost of applying styles, layouts, fills and other things, since it should not change much in different implementations of TodoMVC. I also did not measure the duration of the data transfer.

Methodology


To load pages on Nexus 5, I applied WebPagetest. For each run, a timeline file was created, which was then processed in Big Rig . I took the results from the iPhone and processed them myself, since profiling JavaScript in Safari does not seem to support the export of traces and timelines.

image

Using Big Rig

By the way, that's why I created Big Rig - I wanted to make it easier for all of us to process this kind of data.

Reproduction test


If you want to test it yourself, for example, on a device running Chrome, then follow this algorithm:

Here is an example of how I do it:



results


I received the following data:
FrameworkThe sizeNexus 5 1, 3 boot timeBoot time for iPhone 5S 2, 3
Polymer v1.1.441 Kb 5409 ms233 ms
Polymer v1.2.247 Kb 5155 ms232 ms
AngularJS v1.4.3324 Kb518 ms307 ms
React v0.13.3 [JSX not converted]311 Kb1,201 ms1,463 ms
React v0.13.3 [JSX converted by Babel] 4162 Kb509 ms282 ms
React v0.13.3 [JSX converted; production build] 4, 6160 Kb174 ms118 ms
Backbone v1.2.2 [including jQuery and Underscore]139 Kb248 ms168 ms
Ember v1.10.0-beta.3580 Kb1,992 ms1,440 ms
Vanilla16 Kb50 ms33 ms

Notes:
  1. Tests are performed on Nexus 5 running Chrome 47.
  2. Tests are performed on iPhone 5S running Safari 9.
  3. Bootstrapping involves processing the data in the primary task list.
  4. Cut JSX Transformer. JSX files are converted using Babel.
  5. With the exception of Web Components Polyfill (12 Kb).
  6. Used minifitsirovannaya production-assembly React.

From my point of view, the conclusions are unambiguous: on mobile devices, the use of frameworks is associated with a serious increase in load, especially in comparison with the writing of regular JavaScript. Polymer 1.2.2 showed the best results, but even it turned out to be three times slower than the “vanilla”. React is comparable in speed to Polymer, but I have questions about its scalability .

To really clarify the situation, I note:

Possible objections


Probably, some moments of the test can cause objections, which need to be answered:

$ 64,000 question


And inevitably the question arises: is it necessary to use the framework? I can not give an answer. This should be your own decision. There are a million reasons why you desperately need a framework. Here are my own thoughts on this:

Yes, frameworks offer the developer a lot of comfort. But I can't help thinking that it is better to invest in my own knowledge and skills within the web platform itself. The frameworks come and go, they are like the ebb and flow of the Internet, helping to implement and hone ideas and patterns. But if one day you find out that your favorite framework is no longer working or some important bug has not been fixed, the ability to understand the platform device will provide you with an invaluable service.

In the dry residue


I once wrote that developer comfort is less important than user needs. I still believe in it. Although I am also attracted by the easy life, I do not want to create poorly working products. And I don’t want users to pay a high “price” for them. Now I’m worried about the speed of initial loading of frameworks on mobile devices. But this is only the first step. There are other metrics: memory usage, long load on the CPU, frame rate. In general, we need to look for less costly solutions for users.

If we manage to implement fast-loading frameworks that consume little memory and work with a large frame rate, and even ensure the comfort of development, this would be ideal. But until then, I would prefer to use do without frameworks, at least in the mobile segment.

Source: https://habr.com/ru/post/273613/


All Articles