Monday, November 26, 2007

High-performance JavaScript

**This is my personal blog. The views expressed on these pages are mine alone and not those of my employer.**

An interesting presentation on performance in AJAX app can be found here: http://www.slideshare.net/pureclone/highperformance-javascript

I do not agree with everything (e. g. the author argues against data encapsulation) - while most/all of his suggestions are beneficial in terms of pure perf, if taken as a set they can lead to code that would be very hard to maintain. You have to balance high performance with extensibility/costs of maintenance. If not for these trade-offs, managed languages would not have existed :-).

But overall, extremely useful overview.

Other considerations about performance/JS development that I learned in Gmail:
- use regex expressions whenever possible - they are very fast on all browsers
- on ie6 'a' + 'b' + 'c' + 'd' is excruciatingly slow, and ie7 is better but still not ideal. ['a', 'b', 'c', 'd'].join('') is much faster - create a Java-like StringBuilder object for string accumulations.
- have a library that abstracts certain functionality that browser runtimes implement differently, and compensate for the differences in a single layer, as opposed to the whole app
- have a preprocessor that minimizes function names, inlines accessors, etc - smaller code base really does make a huge difference.
- Use standard programming techniques with JavaScript. Yes, it's a script language, but you will not be able to create a big AJAX app if the code is not readable, well abstracted, and has extensible architecture. Do not cut corners just because it is called script.

**This is my personal blog. The views expressed on these pages are mine alone and not those of my employer.**

1 comment:

DzembuGaijin said...

Yes!!!! Some one finally got it :

SPEED FIRST - FEATURES SECOND !

I am crying form joy :-)