06 September 2008

Google Chrome: Web Kit & V8

Google Chrome web kit V8Web kit is the open source rendering engine that used for Google Chrome. The Google's team impressed by how fast it is. There was a team at Google working on android who said that it uses memory efficiently, was easily adapted to embedded devices and it was easy for new browser developers to learn to make the code base work. Browser are complex one of the things done well with web kit is that it’s kept simple.

Because Javascript is so important to work on building a Javascript virtual machine which is exactly what the V8 team in Denmark did. The V8 team are expert as virtual machines. Whatever language you want to put into into a VM, they can tell us how to write it. Virtual machine provide safety and platform independence. But previous virtual machine for Javascript were designed for small programs, where the performance and interactivity of the system weren’t that important. They just wanted to run some very basic stuff on the webpage. But now, we have web application like Gmail that are using the web browser to its fullest when it comes to DOM manipulations and Javascript and that simplistic approach to Javascript engines isn’t enough anymore. So they started with no code, just some wild ideas about how to make it go really fast such as introducing hidden class transition.

Javascript itself is classless. We can create a new object. Dynamically add properties to it and go on. But in V8, as execution goes on, objects that end up with the same properties will share the same hidden class and we can start applying dynamic optimization based on that. Another factor in V8 speed is dynamic code generation. When other javascript engines run, they look at the Javascript source code and generate an internal representation of it they can interpret. But when we have to do interpretation, we have to look at the structure of your internal representation over and over again. So instead, V8 looks at the Javascript source code and generates machine code that can run directly on the CPU that’s running the browser.

Finally the core design flaw of current Javascript engines is bad garbage collection behavior. Javascript and other modern object-oriented programming languages have automatic memory management. If you don’t have reference to an object anymore, it’s memory can be reclaimed by the system. That’s garbage collection, and it’s a fairly trivial process. But in existing Javascript virtual machines, they use conservative garbage collection which means that because they don’t know exactly where all the pointers are we start searching through the execution stack to see which words look like pointers. But the ones that sort of look like pointers could also be integers that just happen to have the same address as an object in the object head.

Source: http://www.google.com/googlebooks/chrome/


Post a Comment