The web performance story

This blogpost is mostly a reaction to Daniel Clifford’s Google I/O 2012 talk: “Breaking the JavaScript Speed Limit with V8”. I’m reacting only to this talk. I don’t know Daniel Clifford and I have nothing against him personally whatsoever. I think V8 is an excellent product, that’s not what I’m talking about. I would have things to say about the “optimize your code for engine X” trend, but I won’t even talk about that.

I’d like to take a step back to talk about performance in general and focus on as well as criticizing a bit how things are presented in the talk. Once again, although I’ll be mentioning Daniel Clifford in my post but I’m criticizing the talk and not the person.

Why performance matters?

Daniel Clifford’s answer is that better performance allow to do things that weren’t possible, because bad performance was getting in the way of a good experience. I agree with this analysis.

One consequence is that you should care about performance only if either it currently degrades the experience of the product you’re doing or gets in the way of an improvement. If that’s not the case, move on. I’m serious on that point. Too often in technical arguments, people will talk about performance when it actually doesn’t matter since it wouldn’t noticeably improve the user experience.

Performance in software

If we want to talk about web performance, let’s start from the beginning, because improving your JavaScript code isn’t the first thing to care about.

Software architecture

In my opinion, major performance improvements are achieved with good software architecture (this is also true outside of the web context). This field is a very complicated art and very specific to your application, to your needs and your constraints. No one will ever tell you that in a talk, because it is too specific. An architecture consists of deciding which components compose your system, which role each is playing and how they are going to communicate. This is complicated.

Algorithms

This one is also independent of the context of the web. Know your classic algorithms. Know when to use them. Also know when not to use them. For short lists, a bubble sort can be faster than a quick sort.

In “algorithms”, I also put knowing when to use parallelism, knowing the different sort of parallelisms. This isn’t easy, distributed algorithms are not the easiest thing even in a master/workers paradigm.

I’ll get back to this point about algorithms🙂

Web performance

The web has some well-known constraints and it induces things to know to improve performance

Network

As said elsewere, no matter how much computers (CPUs) become faster, light speed won’t increase and the distance between Bordeaux and San Diego is going to stay the same (continental drift aside). This creates an unbreakable physical boundary to speed at which you can transmit a web page. We are not even close to reaching that limit since the transmitted information doesn’t take the shortest path and rarely reach light speed.

As a consequence, reduce the amount of communication and round trips to the minimum. This will be your first major win. Among the practical tips, use HTTP caching and reduce asset sizes.

The DOM and graphics

Since JavaScript has gotten fast, the bottleneck of web scripting is the DOM. DOM objects are weird beast which access isn’t as efficiently optimized than ECMAScript objects. Also, manipulating DOM objects often performs some graphics operation. These are costly. Change things on the screen only when necessary.

Touch the DOM only when needed. Specifically, don’t use the DOM to store information (in data-urls). Use your own objects.

Now, let’s talk about JavaScript

The first advice is knowing the language. It takes time, but it’s worth it to avoid reimplementing inefficiently what the language can do efficiently for you.

Then, write clean modular code (it’s a sort of follow-up of the above “good architecture” advice) and it will do most of the job to avoid useless computation.

If you have followed all the advice above in the provided order (and that’s a LOT of work!) and your application still have a performance issue, now you can start considering following Daniel Clifford’s advices.

Partial conclusion

Above, I’ve tried to step back on performance to explain that engine-specific optimizations are the last thing to take care of (because they yield the smallest benefit by comparison to the other things) because the talk was a bit elusive on that point.

It doesn’t mean knowing JS engines and knowing how to write efficiently for them is a stupid idea. It just mean that’s not the first thing you should care about, and as I said above, in my opinion, it’s the last.

Critique of the rest of the talk

The performance problem to be solved

Compute the 25000th prime number. Quote from the talk (emphasis added):
“I have put together a sample problem that I’d like to talk about throughout the course of this talk. It is a toy problem that I come up with but I think it’s representative of some of the things of some of the performance problem that you might face in your own code

In a very American-bullshit-communication style, we here have a sentence that is purposefully vague and say exactly nothing but uses a lot of well-chosen and confusing words to do so (from what I know, it’s a very cultural thing). Remove the source of vagueness (“I think”, “some” and “might”) and you have a sentence that’s wrong. The very large majority of web developers do not have this problem or a problem related to this sort of heavy computation. For the large majority, the biggest client-side computation issue is probably sorting a bunch of table rows.

I have to admit that I’m annoyed by this attempt to justify something wrongly. Acknowledge that JavaScript performance isn’t an issue for a majority of webdevs and move on! Anyway…

The benchmarked algorithm and the talk conclusion (WARNING: SPOILER!)

After the description of the problem is the description of an algorithm to solve this problem. The algorithm is naive, but this talk isn’t about algorithms, so it doesn’t matter at all.

The talk gives tips to improve JavaScript code for performance. Most of them are legitimate and fortunately concur with good practices. One which brings a major improvement is fixing a bug in the code. The code was reading out of array bounds. Hmm… The example is interesting, but that’s not a performance improvement. That’s just fixing a bug. V8 hasn’t made your code faster. You just made your code correct, it’s dishonest to compare things that do not work the same way.

And the conclusion. One of the biggest scams of all times in the history of tech talks. The algorithm is changed from a linear algorithm to a square-root complexity algorithm. Guess what! 350 times speedup! No kidding!

I guess that’s a Google IO talk, so you’ve got to do a show and show takeaway numbers so people at the end of the talk can say “with V8 you can achieve a 350 times speedup!”, but once again, that’s just dishonest. If your product is really good, why do you need to lie or confuse people? My question is genuine.

Since changing of algorithm is ok to solve the problem faster, I’d like to propose another algorithm which is simple, so I’m convinced will be even faster: function answer(){return 287107;}. But I feel too lazy to benchmark this one…

Conclusion

The talk has valuable advices and I recommend it for this content. However, I’m really unsatisfied of how the talk is constructed and “packaged”. Explanation at the beginning of the web performance priorities would have been good. Also, the couple of scams the talk contains are sad, mostly because they are unnecessary.

45 thoughts on “The web performance story

  1. Unquestionably imagine that that youu stated.
    Your favourite justification appeared to be on the
    net the simplest factor to bear in mind of.
    I say to you, I certainly gett annoyed wnile people
    consider issies that they just do not know about.

    You managed to hiit thee nail upon the highest aand also defined ouut the whole thing without having side effect , people
    can take a signal. Will liukely be back to
    get more. Thank you

  2. I do not know if it’s just me or if everyone else experiencing
    problems with your website. It looks like some of the written text
    within your posts are running off the screen. Can somebody else please
    provide feedback and let me know if this is happening to them too?
    This might be a issue with my internet browser because I’ve had this happen before.
    Appreciate it

  3. Internet marketing is the best solution that
    can ensure the success of your business. Therefore, search engine
    optimization is necessary in order to gain high rankings in the different search engines
    because this is the traffic that will determine the
    fate of your business. You can find information on other
    online marketing methods on the internet.

  4. They have access to online games and browser games which
    involves multiple players and teams. When looked at under a microscope – is our ability to socialize really that
    evolved. Back in 1994, the UK government approved a National Lottery, which helped to make gambling seem more mainstream to the public.

  5. With such positive evidence, Chinese slimming teas are capable of actually
    achieving the weight loss. Invest in a relationship.
    The extract is likewise widely calledgambooge, brindall berry fruit in season1 slice of whole grain crackers, instead of burning the calories from HFCS, as they are packed in. Due
    to this recent study in the mirror, right, when people are dig this misinformed about what you can lose about 2 months.

    Any program, researchers asked the women who had no
    root they withered away.

  6. I think that what you posted made a lot of sense.
    But, think aboutt this, supplose you added a little information? I ain’t suggesting youur
    content isn’t solid, but suppose yoou added a post title to maybe grab people’s attention?
    I mean The webb performance story | Long-term laziness is kinda plain. You should peek at
    Yahoo’s home page and see how they create article headlines to grab viewers to oplen the links.

    You might add a related video or a pic or two to grab people excited abolut what you’ve written. Just my opinion, it would bring your blog a little livelier.

  7. Admiring the time and energy you put into your website and in depth information you present.

    It’s great to come across a blog every once in a while that isn’t the same outdated rehashed material.
    Excellent read! I’ve bookmarked your site and I’m including your RSS feeds to my
    Google account.

  8. I blog frequently and I really appreciate our information.
    The article has truly peaked mmy interest. I’m goinhg to book mark
    your site and keep checking for neww information about once a week.
    I opted in for yur RSS feed as well.

  9. I was suggested tthis website viia my cousin. I’m not surfe whethe this
    submit is written by way of him as no one else recognise
    such particular about my problem. You’re incredible! Thanks!

  10. In questo caso dicono che sia così, qualora stai
    cercando donne il quale la danno gratis per volte è considerato visto come molto semplice
    pensare di trovarle nei siti fama incontri hot.

  11. Hola! I’ve been reading your site for a long time now
    and finally goot the bbravery to go ahead and give you a shout out from New Caney Texas!
    Just wanted to telll you keep upp the fantastic job!

  12. hi!,I really like your writing very much! percentage we communicate extra about your article on AOL?

    I require a specialist in this area to unravel my problem.
    Maybe that’s you! Having a look forward to peer you.

  13. Thanks for the good writeup. It in truth used to be a enjoyment
    account it. Look advanced to far added agreeable from you!

    By the way, how could we keep up a correspondence?

  14. What i don’t understood is in truth how you are now not actually a lot more well-appreciated
    than you might be right now. You are so intelligent. You already know therefore considerably
    in the case of this matter, produced me personally believe it from
    so many numerous angles. Its like men and women aren’t involved unless it’s something to accomplish with Girl gaga!
    Your own stuffs nice. All the time maintain it up!

  15. Wow me encanta el articulo con esas fotos, sin duda esta demasiado bien documentado y sistematizado.
    Lo voy a trasmitir por las redes sociales para que llegue a
    mucha gente, que este articulo merece la pena.

  16. I blog often and I truly thank you for your content. The article
    has really peaked my interest. I will take a note of your blog and keep checking for
    new details about once per week. I subscribed to your
    Feed as well.

  17. This design is incredible! You definitely know how to keep a reader entertained.
    Between your wit and your videos, I was almost moved to
    start my own blog (well, almost…HaHa!) Excellent job. I really loved what
    you had to say, and more than that, how you presented it.
    Too cool!

  18. I think what you published was very logical. However, what about this?
    suppose you composed a catchier post title?
    I am not saying your content isn’t solid., however what
    if you added something that makes people want more?
    I mean The web performance story | Long-term laziness is
    a little plain. You could look at Yahoo’s front page and watch how they create post
    titles to get viewers to click. You might try adding a video or a picture or two to get people interested
    about what you’ve got to say. Just my opinion, it would bring
    your posts a little bit more interesting.

  19. You acttually make it seem sso easy with your presentation but
    I find this mattrer to be actually something that I think
    I would never understand. It seems too complicated
    and very broad for me. I’m looking forward ffor your next
    post, I will try to get the hang of it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s