No video

Google I/O 2012 - Breaking the JavaScript Speed Limit with V8

  Рет қаралды 142,245

Google for Developers

Google for Developers

Күн бұрын

Пікірлер: 52
@Rackforms
@Rackforms 12 жыл бұрын
To summarize: Write your JavaScript as if it were C++ and you'll be fine. Initialize variables at the top of a function, and don't mix types, be it in functions or arrays.
@JoshuaPack
@JoshuaPack 9 жыл бұрын
No matter what language you build your application in, always make sure you know how your language works so you can have optimized code.
@srcmake
@srcmake 5 жыл бұрын
Amazing talk. Your examples and explanations were perfect and weren't too technical.
@mraleph
@mraleph 12 жыл бұрын
zval under the hood is just a tagged union. tagged pointers (like V8 does it) or NaN-tagging (used by SpiderMonkey, JavaScriptCore) are compact ways to represent tagged unions. they allow to reduce memory footprint and make passing tagged values around faster e.g. tagged pointer will occupy one machine word and can be stored in a single machine register while zval would require several registers.
@lennyhome
@lennyhome 11 жыл бұрын
Now opening popups even faster with JavaScript!
@siliconmalta2349
@siliconmalta2349 6 жыл бұрын
i had the feeling adding new properties affected performance, great to know
@mraleph
@mraleph 12 жыл бұрын
JavaScript engines share some design decisions so most of them suffer from the same things. If you try this example in FF/Safari you will see that performance improves there as well. In C++ you can read out-of-bounds, whether you get an error or not depends only on a memory layout. In this particular case you never actually read out of bounds, you just read an uninitialized part of an array. And C++ actually does the same (even worse: prime_count is uninitialized).
@mraleph
@mraleph 12 жыл бұрын
example demonstrates two very important things: corner cases that V8 does not like (out-of-bounds reads, arithmetic with undefined value) and a technique that can be universally applied to optimize virtually any JavaScript code.
@MichaelQuad
@MichaelQuad 5 жыл бұрын
how to run chrome on windows with those trace flags now? it doesnt run with --trace-bailout. ive tried dbgview.exe, not much use. also, ive read you record about, here mrale.ph/blog/2012/06/21/v8s-flags-and-chrome-on-windows.html can you drop some link with manual maybe?
@JParril
@JParril 11 жыл бұрын
That's fair. He probably should have used an example that wasn't such an obvious mistake. But to say v8 isn't javascript is a little harsh, javascript isn't v8, and v8 does things differently than most engines, but they're smart enough to avoid memory leaks when using outbound locations in an array. I think he actually mentioned growing large arrays as the correct convention.
@mojacc1
@mojacc1 9 жыл бұрын
Great presentation, I have learned a lot of it
@kamtschatkas
@kamtschatkas 12 жыл бұрын
Haha i was watching this video and i was wondering all the time, what happened to michael. I am glad that you told us at the end!
@essellar
@essellar 11 жыл бұрын
The *actual* point is that something that would be a crash error (or something more disastrous) in another language may simply result in allocation/conversion costs in JavaScript. At the *language level*, JS doesn't *have* arrays as they are normally constructed; the creation of arrays (as opposed to dictionaries) is a JIT/run-time optimization (and there are still no hard bounds). There is no "out of bounds", there is only accessing unassigned members.
@aknewhope
@aknewhope 10 жыл бұрын
Very good presentation.
@dmh20002
@dmh20002 12 жыл бұрын
i would amend that to say 'write JS like C rather than C++'. what you said plus - no function argument type overloading - no try/catch
@liux0229
@liux0229 12 жыл бұрын
Great talk. Seems like the JS code is actually calculating the 24999th prime? You insert 1 into the array too that's why iterating from index 1 instead of 0 works. The example seems a little bit contrived - the codie isn't terribly great to begin with.
@Jon47
@Jon47 11 жыл бұрын
Really awesome talk, thank you!
11 жыл бұрын
It's not a bug, it's a feature. Javascript, unlike C++ but much like other scripting languages, was always intended for the speed of development rather than execution.
@webgpu
@webgpu 6 жыл бұрын
Summary is: initialize your data first (instead of just assuming default values for variables / array elements) and avoid changing data type for any variable / array element. That's all. (funny [and kinda obvious] that those things aren't permitted in common strong-typed languages like C, Java, etc)
@stokescomp
@stokescomp 12 жыл бұрын
very good information, thanks
@Dieterbe
@Dieterbe 12 жыл бұрын
so to clarify, i think this is just one of those cases where people think "working on performance is fun and interesting, now i just need to utter some phrases to justify it". don't get me wrong, i agree the performance stuff can be fun and useful, but you can't really provide a general (in scope) rational justification without sounding hollow.
@xTriad
@xTriad 12 жыл бұрын
He adds the optimization on a subsequent slide.
@bernd_the_almighty
@bernd_the_almighty 11 жыл бұрын
As a user I haven't experienced any change. Sites from today feel pretty much like before the whole JS ending war started. The speed gains are marginal outside synthetic tests unless you try to play a JavaScript port of Quake in the browser...
@digerpaji
@digerpaji 12 жыл бұрын
cool talk...can anyone explain why tagging is better than Z-vals (used in php)?
@notarealhandle123
@notarealhandle123 8 жыл бұрын
This is kind of funny, that after so much talking about that primes calculation algorithm and optimizing the heck out of it you arrived with 0.044s to calculate the 25,000th prime. Also your calculation is wrong, you calculated the 24,999th prime, by the way (the first prime is 2), and the 25,000th prime is 287117. I didn't know most of what was explained in the video, but in my first take at the primes calculation it took only 0.025s to calculate the 25,000th prime :) Talking about optimization here, huh! :) Here's the entire test: function nextPrime(value) { if (value > 2) { var i, q; do { i = 3; value += 2; q = Math.floor(Math.sqrt(value)); while (i
@moonbeam7434
@moonbeam7434 8 жыл бұрын
+Vitaly Tomilov If you use a Sieve you can get faster results for calculating higher primes. However, this wasn't about the fastest prime calculation, it was just used to explore the V8 and how you can use general concepts to optimize any code. At least that's what I got out of it.
@segankuz
@segankuz 12 жыл бұрын
very impressive!
@Lil1Tommy
@Lil1Tommy 11 жыл бұрын
Really true been please help really tru how do it fix on Ipad 2 new KZfaq Application Crash Your Last Session Closed Unexpectedly Send A Crash Report?
@Lil1Tommy
@Lil1Tommy 11 жыл бұрын
How fix on Ipad 2 new KZfaq Application Crash Your Last Session Closed Unexpectedly Send A Crash Report?
@Igosuki
@Igosuki 12 жыл бұрын
Very cool
@MichaelQuad
@MichaelQuad 5 жыл бұрын
im failed to configure --js-flags on windows. any modern manual?
@tommasoallevi4223
@tommasoallevi4223 8 жыл бұрын
How can I install mac-tick-processor tool? Thanks
@ozezieszies1502
@ozezieszies1502 11 жыл бұрын
Would. I need help.my java have something broke
@DearLuck
@DearLuck 11 жыл бұрын
Can Google fix youtube so it buffers at least Google's videos?
@hrgwea
@hrgwea 12 жыл бұрын
@ 6:40 he forgot to enable optimizations with the -O3 option, otherwise the comparison is unrealistic.
@JohnLeidegren
@JohnLeidegren 4 жыл бұрын
Actually, it was intentional kzfaq.info/get/bejne/i7CAl8upmuC4kas.html
@pumpbreaks
@pumpbreaks 12 жыл бұрын
so basically, V8 rocks
@JParril
@JParril 11 жыл бұрын
But it's not a bug. If the code is correct javascript, but slow javascript, that is not definable as a bug.
@JParril
@JParril 11 жыл бұрын
This is a big problem to developers. The reason you haven't seen a change in performance is because the browsers don't do anything that requires performance to run. If a webpage pauses for a noticeable amount of time in IE6 than that web page is broken. The goal here is not to have performance which is noticeable to guys like you, who don't do anything interesting with a browser. It's to make interesting things possible. In the mean time, you can enjoy the spell check, firewall, and advanced UI.
@Dieterbe
@Dieterbe 12 жыл бұрын
2:15 performance matters because "every cycle that you win back when you do performance optimisation you can invest in something new that you haven't been able to do before". what a hollow marketing phrase. "every cycle"? = clockcycle? if the goal is to do new things you haven't been able to do before, I would say first figure out what's required to allow you to do the new thing, usually it's actually writing the code for the new thing
@ozezieszies1502
@ozezieszies1502 11 жыл бұрын
Ola..hi..gd.afternoon..can.somebody..talk.with.mee..perhap..i need a someimportant to talk..oze..with all my webmaster and all developer..s.o.s
@agcouper
@agcouper 9 жыл бұрын
In my opinion, this really shows how bad JavaScript is as a programming language. People been complaining for ages how easy it is to shoot yourself in the foot with C++, but it seems to me that JS is even worse in this regard. I wish the language itself was progressing with the same speed as JS engines.
@SvetlioPrice
@SvetlioPrice 8 жыл бұрын
+Leonid Romanov Oh, please. While there are some things you can't get around - imprecision with numbers, type madness, you will only shoot yourself in the foot with JS if you are not familiar with the language. Not to mention how many improvements ES6 brings - block level scope, cleaner syntax, new data structures, etc. JavaScript is progressing just fine.
@agcouper
@agcouper 8 жыл бұрын
SvetlioPrice You know what: I take my words back. The thing is, I used to program in C++ many years ago and I'm still interested in the language. So, recently I've watched a number of videos about C++ 14 and oh, boy, did I remember all the quirks of C++. JS is much better in this regards. While you can't compare the languages itself, for obvious reasons, you can compare the pain caused by it's quirks, and JS is definitely less painful.
@pranaydubey6782
@pranaydubey6782 8 жыл бұрын
+Leonid Romanov No language is good or bad. People who say c++ or JS or any other language is bad, its either don't understand the language, are so attached to a particular programming language, or it just doesn't suits their needs. Every programming language has its pros/cons and its upto you what suits your needs. I work as a web developer where I use JS all the time and I love it, but I also compete in competitions where I hate it at times where I can't optimise it for speed, and move to c++ which makes optimisation a breeze. If you're going to build a CPU intensive server, use c++, if you need concurrency,I/O and very little server processing go with stack like nodejs,ruby etc. But no programming language is one size fits all and probably never will be.
@lucasvvop
@lucasvvop 7 жыл бұрын
Every language has its pros and cons and can be very powerful if you know how to use it properly.
@tjalferes
@tjalferes 5 жыл бұрын
11:34
@JamesNewton
@JamesNewton 12 жыл бұрын
Actual talk starts at 10:00... before that it's fluff.
@thattechguy1398
@thattechguy1398 7 жыл бұрын
Well I watched the whole video to find out that his friend is fine.
@ripsawridge
@ripsawridge 12 жыл бұрын
Oh man am I embarassed now :D
Google I/O 2011: Learning to Love JavaScript
1:03:26
Google for Developers
Рет қаралды 234 М.
What are AI Agents?
12:29
IBM Technology
Рет қаралды 173 М.
Gli occhiali da sole non mi hanno coperto! 😎
00:13
Senza Limiti
Рет қаралды 16 МЛН
黑天使遇到什么了?#short #angel #clown
00:34
Super Beauty team
Рет қаралды 43 МЛН
Google I/O 2011: JavaScript Programming in the Large with Closure Tools
57:07
Google for Developers
Рет қаралды 75 М.
How This New Battery is Changing the Game
12:07
Undecided with Matt Ferrell
Рет қаралды 125 М.
Google I/O 2012 - The Web Can Do That!?
43:07
Google for Developers
Рет қаралды 196 М.
The Story of Next.js
12:13
uidotdev
Рет қаралды 564 М.
V8, modern JavaScript, and beyond - Google I/O 2016
36:58
Chrome for Developers
Рет қаралды 45 М.
Google I/O 2012 - Better Web App Development Through Tooling
48:25
Google for Developers
Рет қаралды 117 М.
Google I/O 2009 - V8: ..High Performance JavaScript Engine
1:01:09
Google for Developers
Рет қаралды 33 М.
How I Made JavaScript BLAZINGLY FAST
10:10
ThePrimeagen
Рет қаралды 216 М.
Why is anti-immigration sentiment on the rise in Canada?
13:00
The Guardian
Рет қаралды 1,8 МЛН
Gli occhiali da sole non mi hanno coperto! 😎
00:13
Senza Limiti
Рет қаралды 16 МЛН