Scaling JavaScript to Large Web Applications
Thursday, May 21, 2009
The V8 JavaScript engine has been designed for scalability. What does scalability mean in the context of JavaScript and why is it important for modern web applications?
Web applications are becoming more complex. With the increased complexity comes more JavaScript code and more objects. An increased number of objects puts additional stress on the memory management system of the JavaScript engine, which has to scale to deal efficiently with object allocation and reclamation. If engines do not scale to handle large object heaps, performance will suffer when running large web applications.
In browsers without a multi-process architecture, a simple way to see the effect of an increased working set on JavaScript performance is to log in to GMail in one tab and run JavaScript benchmarks in another. The objects from the two tabs are allocated in the same object heap and therefore the benchmarks are run with a working set that includes the GMail objects.
V8's approach to scalability is to use generational garbage collection. The main observation behind generational garbage collection is that most objects either die very young or are long-lived. There is no need to examine long-lived objects on every garbage collection because they are likely to still be alive. Introducing generations to the garbage collector allows it to only consider newly allocated objects on most garbage collections.
Splay: A Scalability Benchmark
To keep track of how well V8 scales to large object heaps, we have added a new benchmark, Splay, to version 4 of the V8 benchmark suite. The Splay benchmark builds a large splay tree and modifies it by creating new nodes, adding them to the tree, and removing old ones. The benchmark is based on a JavaScript log processing module used by the V8 profiler and it effectively measures how fast the JavaScript engine can allocate nodes and reclaim unused memory. Because of the way splay trees work, the engine also has to deal with a lot of changes to the large tree.
We have measured the impact of running the Splay benchmark with different splay tree sizes to test how well V8 performs when the working set is increased:

The graph shows that V8 scales well to large object heaps, and that increasing the working set by more than a factor of 7 leads to a performance drop of less than 17%. Even though 35 MB is more memory than most web applications use today, it is necessary to support such working sets to enable tomorrow's web applications.

10 comments:
Christopher said...
You may want to mention that the version 4 link should only be opened in Chrome. Out of a morbid sense of curiosity, I clicked it in IE8 and it almost crashed my system.
May 21, 2009 2:04 PM
Benni Bennetsen said...
didnt crash in IE8, but it's hopeless to run yes :D
Fortsæt det gode arbejde, jeg er virkelig glad for Chrome (mangler blot mine extensions fra FF)
May 21, 2009 2:20 PM
rbmcnutt said...
My local scores were:
IE 8 Score: 45.2
Firefox 3.0.1 Score: 162
Safari 4 Beta Score: 966
May 22, 2009 12:30 PM
Matthew said...
Bring on the feature bloat! Like all browsers before it, to justify the continued existence of people working on it, new features will need to be added, these features will slowly erode what makes Chrome great, it's simple interface and speed.
I'm looking at you firefox.
May 24, 2009 1:13 PM
Luis said...
We all know about the great speed of V8 compared to other javascript engines, but just to have a clear picture of its real speed, how does it compare to a traditional compiled language (c, c++, java, etc)?
I haven't seen any comparison so far...
June 19, 2009 2:01 PM
onuryenc said...
V8 BS scores;
IE8 : 32
Firefox 3.5 : 226
Safari 4 : 1060
Acid3 test scores;
IE8 : %20
Firefox 3.5 : %93
Safari 4 : %100
June 24, 2009 7:36 PM
chris.cappuccio said...
I've been using the latest Midori+WebKit on OpenBSD, which gets 100/100 on ACID3 and smokes the v8 test on my lowly celeron 1.6ghz. Who needs chrome? :)
July 8, 2009 4:50 PM
Alana said...
I recently came across your blog and have been reading along. I thought I would leave my first comment. I dont know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.
Maria
http://memory1gb.com
August 6, 2009 12:45 AM
Sonic1980 said...
November 2, 2009 9:09 AM
Sonic1980 said...
This is a Gameboy emulator written in pure Javascript.
http://www.codebase.es/jsgb
V8 gives full speed, even on simple netbooks. Other JS engines are very slow compared to V8 in real world programs (not simple loop-benchmarks)
November 2, 2009 9:11 AM
Post a Comment