Vyacheslav Egorov on Benchmarking JavaScript Performance | GOTO 2015

UGtastic Archive

Vyacheslav Egorov on Benchmarking JavaScript Performance | GOTO 2015

Loading this player connects your browser to Youtube.

Full Transcript Available
LIVE CC UGtastic Archive

Press play or click any turn in the transcript to start real-time synchronized playback...

Hi, it's Mike with UGtastic . I'm here at GOTO Conference 2015, and I'm sitting here with Vyacheslav Egorov, who gave a talk on benchmarking JS. Hi, it's Mike with UGtastic . I'm here at GOTO Conference 2015, and I'm sitting here with Vyacheslav Egorov, who gave a talk on benchmarking JS. JavaScript performance is a critical aspect of web development. Vyacheslav Egorov explains why many benchmarks are incorrect and provides insights into optimizing your JavaScript code.
The Interviewer

Mike Hall

Interviewer, UGtastic

The Guest

Vyacheslav Egorov

benchmarking JavaScript performance

The Conversation


Mike Hall Interviewer, UGtastic ▶ Speaking
Hi, it's Mike with UGtastic . I'm here at GOTO Conference 2015, and I'm sitting here with Vyacheslav Egorov, who gave a talk on benchmarking JS. Thank you very much for taking the time to speak with me. When you talk about benchmarking JS, are you talking about client-side JS?
Vyacheslav Egorov benchmarking JavaScript performance ▶ Speaking
I mean, JS lives in a lot of different places.
Mike Hall Interviewer, UGtastic ▶ Speaking
Is this Node? Is this browser JS? What are you benchmarking?
Vyacheslav Egorov benchmarking JavaScript performance ▶ Speaking
So, I don't have any particular focus. I'm just looking at the pure JavaScript performance. So, it doesn't matter if you run your JavaScript on the client-side or server-side. Basically, no matter where you are, my talk applies to you.
Mike Hall Interviewer, UGtastic ▶ Speaking
Okay.
Vyacheslav Egorov benchmarking JavaScript performance ▶ Speaking
So, you know, even if I'm in V8 or Rhino or whatever, it's going to be...
Mike Hall Interviewer, UGtastic ▶ Speaking
Okay, so, when you talk, what techniques and tools were you talking about? Where did this talk come from? What experiences did you have that led you to this?
Vyacheslav Egorov benchmarking JavaScript performance ▶ Speaking
Well, I used to work on the V8 team, and when you work on a team of the VM engineers, you usually get different questions from the users, in this case, JavaScript developers, who don't completely understand what happens inside the VM and how they should measure performance of their code. And that's what this talk is based on. Basically, I monitor different social media, and I see people posting different benchmarks, and I look what happens there, and I explain why these benchmarks are usually incorrect. And that's, yeah, that's basically my experience.
Mike Hall Interviewer, UGtastic ▶ Speaking
So, what are some of the things that you see that are incorrect, and like, what are some quick tips, or articles people should read or try to understand better about JavaScript performance?
Vyacheslav Egorov benchmarking JavaScript performance ▶ Speaking
I think the biggest issue is that people still think that JavaScript implementations are very dumb, but these implementations are quite smart. So, I think that that's the main thing that they should know about that, and they should always account for the very advanced optimizations that the JS engines are capable of doing now. So, there is no really single tip. They should just try to understand what is happening on the inside.
Mike Hall Interviewer, UGtastic ▶ Speaking
Okay.
Mike Hall Interviewer, UGtastic ▶ Speaking
Now, if you're dealing with V8 optimization, one of the things is that JavaScript runs anywhere, on V8, Rhino, different browsers. Does the wisdom of "this is good for JavaScript performance" apply generally everywhere? Or do you find people benchmarking on V8, and then when they try a different VM they see very different performance characteristics?
Vyacheslav Egorov benchmarking JavaScript performance ▶ Speaking
Sometimes that happens, but these days, the implementations really converge on, they apply the same techniques, so it's quite often that you see the same performance characteristics across all of the platforms you use. That's why this talk is quite universal, and this issue is quite universal.
Mike Hall Interviewer, UGtastic ▶ Speaking
Okay, and when you're looking at the way JavaScript is being implemented, I mean, I've heard people on Twitter tweeting about, you know, if you're trying to implement a class structure in JavaScript, don't reimplement the classical inheritance structure, use the prototypal inheritance and different ways of structuring your application. Does that play into the way people reason about writing JavaScript, and its performance? If I'm implementing a class in JavaScript, is that generally gonna perform worse or better than if I do something more native?
Vyacheslav Egorov benchmarking JavaScript performance ▶ Speaking
So the thing is that JavaScript engines evolve naturally, so they follow the paths that people are using, so they optimize for the patterns that people are using. In this sense, if you use, for example, constructors and prototypes, this is actually the most performant way of writing JavaScript, especially if you keep everything, like, kind of static. Yeah, you just follow the common patterns and then you will be safe.
Mike Hall Interviewer, UGtastic ▶ Speaking
Okay, and as far as working on the V8 engine itself, I didn't realize it before our conversation. How did you get involved in working on V8, which has become something of an industry change? Not just with Chrome, but with Node being built on that. You're working on some pretty intense technology.
Vyacheslav Egorov benchmarking JavaScript performance ▶ Speaking
So, well, I stopped working on V8 three years ago, but I was doing the Java VM before back in Russia, and then V8 people were searching for a person with a compiler background, and they hired me, so I joined the team. I worked on different parts of V8, from garbage collection to compiler infrastructure. So I have the background in this, and that background seems to fit with what the team needed.
Mike Hall Interviewer, UGtastic ▶ Speaking
Right. Okay, you described two things earlier. One is that JavaScript implementations are much smarter than people give them credit for, and that the current patterns of how people write their applications are being used to derive how these JS VMs work. Is there something, a common pattern that people are using, that you kind of wish they would just move away from? Like, even though we have classical class and inheritance, but if they wrote their JavaScript a different way, it would be a lot more efficient?
Vyacheslav Egorov benchmarking JavaScript performance ▶ Speaking
And they might get a lot more native, and they might get a lot more benefits that they don't see now.
Mike Hall Interviewer, UGtastic ▶ Speaking
Is there anything, any advice or observations you've made?
Vyacheslav Egorov benchmarking JavaScript performance ▶ Speaking
No, I actually have an opposite issue. So, the, the JavaScript VMs, even though they are quite smart, they still, because they evolve by following what people do, they are very focused. So, what I really want them to do is to start expanding this area of fast JavaScript and support, like, different corners of the language they do not support well, or they just fall to the slow path, and so on. So, it's actually the other way around.
Vyacheslav Egorov benchmarking JavaScript performance ▶ Speaking
Not the people.
Mike Hall Interviewer, UGtastic ▶ Speaking
Well, no, you're saying you wish they would do more of, be aware of these other types of structures?
Vyacheslav Egorov benchmarking JavaScript performance ▶ Speaking
Yes, exactly.
Mike Hall Interviewer, UGtastic ▶ Speaking
Yeah. Yeah. So you are a little bit frustrated with it, like, "Hey, we're just going to do this one type of structure, but JavaScript is so much more than that."
Vyacheslav Egorov benchmarking JavaScript performance ▶ Speaking
Precisely.
Mike Hall Interviewer, UGtastic ▶ Speaking
Okay, great. Well, thank you very much for taking the time to speak with me.
Vyacheslav Egorov benchmarking JavaScript performance ▶ Speaking
Thank you. I appreciate it.
Mike Hall Interviewer, UGtastic ▶ Speaking
All right, thank you.

Critical Insights


durable
"JavaScript engines are smarter than many developers realize."
durable
"Classical inheritance in JavaScript is often less efficient than using prototypal inheritance."
durable
"Performance patterns in JavaScript are evolving based on common usage."