Let's have a look under the hood of V8 to understand how this works. To reduce the overall time spent compiling, V8 defers compilation of JavaScript functions until immediately before they are executed the first time. This compilation phase is fast but doesn't focus on optimizing the code, just on getting it don e quickly. In V8, pieces of code that are executed very often are compiled a second time by a specialized optimizing compiler. This second compilation pass makes use of many advanced optimization techniques, meaning it takes more time than the first pass but delivers much faster code.
Until now, V8 took turns compiling optimized Javascript code and executing it. For large pieces of code this could become a nuisance, and in complex applications like games it could even lead to stuttering and dropped frames. Concurrent compilation tackles this issue.
The graphs below show excerpts of V8's vital signs when running Mandreel, part of the Octane benchmark suite, on the Nexus 5 phone. The graphs have been created using our new profiling visualization tool. The black bar represents execution of JavaScript, and ideally would be solid.
The first graph shows V8 running without concurrent compilation. V8 is fully occupied with optimizing a large piece of code, causing an execution pause of more than 600ms.
Concurrent code compilation is another step towards reducing latency in Chrome and is part of various ongoing efforts to deliver more responsive, smoother web applications.
Posted by Yang Guo, Multi-threaded V8 Engineer
Source: http://blog.chromium.org/2014/02/compiling-in-background-for-smoother.html
0 comments:
Post a Comment