V8: an open source JavaScript engine

I’m Lars, and I’m the tech lead for the V8 project, and the V8 project is a new, exciting,
high-performance JavaScript engine we built here at Google.
The V8 team is located in Aarhus, Denmark, but we also have a few people working on the
project here from JavaScript was written and designed to be
a way of customizing conversation inside the browser, so if you press the button, you could
do different things. So it allowed the programmer to change the
behavior of the browser. In the beginning, it was only meant to be
a small piece of code you added to your Web application.
One of the interesting properties of JavaScript and the reason why it’s being used today is
that it’s platform-independent. So you can run on Mac OS or Windows and use
the same application inside the browser. Let me talk about the three key design decisions
we did in V8. The first one is hidden classes.
The second one is a generated code. And the third one is the efficient memory
management system we have. So first I want to show you how we have introduced
hidden classes in our system. As you all know, JavaScript is prototype-based,
and if you have a function here called Point, where we create a new optic and assign X and
Y to the parameters, and here, the last two lines, we’ll create two different Points,
where X and Y is zero and one, and two and three.
In most JavaScript implementation, you will have two independent optics that will not
share any common structure. That’s different in V8.
So here’s a drawing of what we do in V8. You have the two different optics, A and B,
and instead of having them being completely independent, like in most JavaScript implementation,
we actually make them share a hidden class. So instead of creating two optics, we create
three: A and B, and then the hidden class for these two Optics.
The hidden class will actually explain that both these two optics have the same number
of properties– namely, two, and then X and Y. Now, how are we going to use this?
Well, let me show some generated machine code we do in V8.
So another idea in V8 is that we translate JavaScript code into machine code, instead
of just using interpreter to obtain speed. And let’s take an example.
If you actually have some application that uses a Point– here, we symbolize with point.x–
it reads the X property out of a point. And here you have the code we actually generate
for it. So this is X86 code, and instead of having
a complicated look-up of a property, we can actually do much better if we have a hidden
class structure. So, as you see in this case, reading an X
property of an optic will translate into three machine instructions.
The first instruction will actually check that the optic has a certain hidden class.
If it has that, it will continue to the third instruction, and then just read the X property
out of the optic. Otherwise, we call a run-time routine.
Now, when you’re dealing with the code, we do not know about the hidden classes, so this
code here is classical, and we capitalize on the hidden classes to make it run fast.
In essence, instead of having a generic look-up for a property, we can actually generate efficient
machine code to fetch the property out of the optic, like any other class-based system. The third thing we wanted to solve in V8 was,
we wanted to eliminate garbage collection process.
And so, we designed this efficient memory management system that allowed fast allocation
and also minimal process when running JavaScript. And that actually means when you, as a user,
use JavaScript inside the browser, you will not get any hiccups with your having tagged
your applications. In particular, if your application is big,
then you tend to have lots of process. We eliminated that by implementing a two-generation-based
garbage collector, so that when we reclaim storage for updates, we do it in small pieces.
It sounds like a simple problem, but in JavaScript, you are always reading in JavaScript, compiling
code, creating hidden classes, and so on. In V8, all these kinds of optics that are
created at one time, they reside inside the optic key, and they are reclaimed incrementally
as you execute. So V8 is an open source project, and Chrome
underdog is also including it as part of the Google Chrome browser.
You can also take it as a separate stand-alone project and embed a new application.
So the main purpose of V8 is to raise the performance bar of JavaScript out there in
the marketplace.

99 thoughts on “V8: an open source JavaScript engine

  1. I am North American. I speak Spanish and that's because I lived in a Spanish speaking country for awhile. I could never do this presentation in Spanish. I find English speakers who are ignorant and cannot actually speak a second language themselves are the most discriminating. Lars actually speaks English quite well!

  2. How can we feedback about the subtitles? Every time Lars says "object" the subtitle says "optic"…

  3. Nice video overview of V8. Whoever translated the subtitles knows NOTHING about software development. Most of the keywords are completely mistranslated. If Google wants to email me the text of the transcript, I would be happy to correct it and mail it back. Just let me know.

  4. The subtitles are great. It seems he's talking about physics, b/c it says "optics" a lot. Like in: create a new optic.


    I LOVE GOOGLE (just a fanboi)

  5. No, he *clearly* meant OBJECT, not optic. But due to his accent, it comes out sound like optic. What is interesting is if the CC is being done by AI or by human?

  6. I just installed v8 on my machine to embed it in a webserver that executes JS files. I was amazed in how easy it was to get my first Hello World from a JS file.

  7. BTW, the subs were clearly done by a human–the computer-generated CC would do an even worse job with his accent! Perhaps they should have had him proofread the CCs.

  8. The way they compile javascript on the fly is even more amazing then the JIT in the CLR from Microsoft's .Net Framework.
    JavaScript has no rules, everything can be anything, that's making it a hell…
    Well it's great, and with de Google Chrome Frame for IE, you have a reasonable speed at all browsers.
    I wonder if Microsoft decided to use V8 in IE9… Let's hope so, well at least they got CSS3.

  9. Best work for humanity…demonopolizing companies that rip off developers…u gotta buy a mac to develop for the iphone and then pay them money what kind of BS is that…with javascript developers can be creative and just focus on the product rather than gettin screwed by apple and microsoft.

  10. @digerpaji Good luck getting the free marketing advertising, and distribution that comes with a meager 100 dollars a year Apple Developer package. This also includes an incredible IDE / UI, access to extremely responsive forum support, and if yo use all Java, porting to Android, BB, or any java machine should be quite easy. Also cant you write Java Apps in any text editor, like MS Word, BB Edit ? I really dont know myself, but I thought JAVA ( minus objects) are basically runtime text.

  11. Neither did I. Now go implement Javascript's object model in it. Yeah, it's "hardly achievable". That's why games aren't made in ASM.

  12. I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.
    I love V8. Ich liebe V8.

  13. Google, there's one problem with your garbage collection.

    It doesn't remove properties from arrays when you delete them (delete array[index];), It leaves a null property in the array instead of completely removing it like it does in objects, so after performing a delete, the array will look like this [0, 1, null, 3] instead of what I assume it should look like, [0, 1, 3]

  14. That's not true. A simple test:
    var t = [0, 1, 2, 3];
    delete t[2];
    gives [0, 1, undefined × 1, 3], just as it should.

  15. That is a problem when you need the index numbers to be exact.

    When using a for loop to run through an array, and using the iterator to number blocks that represent part of the array, it will either say null, or if you check if the index exists before writing, blatantly skip a number, which leads to having to make your own garbage collection method to remove the offending index so the structure doesn't suffer.

    This is exactly the problem I ran into when making a tabbed notepad webapp.

  16. Interesting. Do you have a code snippet to share? I can't reproduce it with simple for in iteration.

  17. I recreated the problem here:


    What I ended up having to do in the original file was make my own garbageCollection function that methodically builds a second array on the existing values and returns that instead, like this update:


    If arrays had garbage collection, a null value wouldn't be left in the array, and I wouldn't have to use that potentially performance-threatening function.

    System/Browser: Ubuntu QQ/Chromium.

  18. Well, this jsFiddle doesn't recreate the problem, you hard-coded values written in local storage, the problem must have appeared before. This snippet, as you created it, returns, obviously, null everywhere: Firefox, Opera, etc. 🙂

  19. Well, I recreated the result, specifically, to show why it can be a problem.

    But, the cause of the null value specifically was the delete keyword, as in this summary of what the "-" button does:

    removeTab = function(){
    delete Tabs[Tabs.length-1]

    However, just a minute ago I found out there's an Array.prototype.pop() function which seems to entirely remove the last index of an array. [1,2,3] becomes [1,2].

  20. he would probably know that and doesn't need you to point it out !!!
    should be thankful he's speaking English instead of putting up a goddamn caption underneath

  21. No, because if you the same thing on an object, it deletes the entire thing.

    obj = {0:0, 1:1, 2:2};

    delete obj[1];

    obj => {0:0, 2:2}

    While in an array, you have to build your own "garbage collection" method to purge the null value so it doesn't clog up your JSON string.

  22. Give your next presentation in Danish, and see how it goes for you. Send me a copy, so I can point and laugh.

  23. well, Google created a self subtitled system that scan your video and then post that in the video for thows who want subtitle.

  24. I literally started a search for "javascript vv8 optics" thinking, "I bet it's some weird new object design pattern that will take days of reading to-oh…nevermind.." as I read this post…:

  25. no offense but while this is an informative intro to hidden classes it was like a dictionary defining a word by using a more complex word. the idea of explaining javascript by showing CUSTOM assembler code is a bit wrong audience.
    and I get JNZ (jump not zero) and such I use to program machine code in hex not assembler. And this is the old Basic and C code using machine for speed (realtime functions) method. of course "function" and "method" mean different things in the OOP world of "objects".

  26. i like js and java but this statements are so exagerated : "Javascript platform independent", "Java platform independent"

  27. Is java script an interpreted language, not a compiled language? If yes then what works does V8 js engine do?

  28. Great Stuff. Watch another video after this one: https://youtu.be/p-iiEDtpy6I to get more info on V8 internals.

Leave a Reply

Your email address will not be published. Required fields are marked *