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.
@JoshuaPack9 жыл бұрын
No matter what language you build your application in, always make sure you know how your language works so you can have optimized code.
@srcmake5 жыл бұрын
Amazing talk. Your examples and explanations were perfect and weren't too technical.
@mraleph12 жыл бұрын
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.
@lennyhome11 жыл бұрын
Now opening popups even faster with JavaScript!
@siliconmalta23496 жыл бұрын
i had the feeling adding new properties affected performance, great to know
@mraleph12 жыл бұрын
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).
@mraleph12 жыл бұрын
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.
@MichaelQuad5 жыл бұрын
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?
@JParril11 жыл бұрын
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.
@mojacc19 жыл бұрын
Great presentation, I have learned a lot of it
@kamtschatkas12 жыл бұрын
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!
@essellar11 жыл бұрын
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.
@aknewhope10 жыл бұрын
Very good presentation.
@dmh2000212 жыл бұрын
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
@liux022912 жыл бұрын
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.
@Jon4711 жыл бұрын
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.
@webgpu6 жыл бұрын
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)
@stokescomp12 жыл бұрын
very good information, thanks
@Dieterbe12 жыл бұрын
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.
@xTriad12 жыл бұрын
He adds the optimization on a subsequent slide.
@bernd_the_almighty11 жыл бұрын
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...
@digerpaji12 жыл бұрын
cool talk...can anyone explain why tagging is better than Z-vals (used in php)?
@notarealhandle1238 жыл бұрын
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
@moonbeam74348 жыл бұрын
+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.
@segankuz12 жыл бұрын
very impressive!
@Lil1Tommy11 жыл бұрын
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?
@Lil1Tommy11 жыл бұрын
How fix on Ipad 2 new KZfaq Application Crash Your Last Session Closed Unexpectedly Send A Crash Report?
@Igosuki12 жыл бұрын
Very cool
@MichaelQuad5 жыл бұрын
im failed to configure --js-flags on windows. any modern manual?
@tommasoallevi42238 жыл бұрын
How can I install mac-tick-processor tool? Thanks
@ozezieszies150211 жыл бұрын
Would. I need help.my java have something broke
@DearLuck11 жыл бұрын
Can Google fix youtube so it buffers at least Google's videos?
@hrgwea12 жыл бұрын
@ 6:40 he forgot to enable optimizations with the -O3 option, otherwise the comparison is unrealistic.
@JohnLeidegren4 жыл бұрын
Actually, it was intentional kzfaq.info/get/bejne/i7CAl8upmuC4kas.html
@pumpbreaks12 жыл бұрын
so basically, V8 rocks
@JParril11 жыл бұрын
But it's not a bug. If the code is correct javascript, but slow javascript, that is not definable as a bug.
@JParril11 жыл бұрын
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.
@Dieterbe12 жыл бұрын
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
@ozezieszies150211 жыл бұрын
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
@agcouper9 жыл бұрын
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.
@SvetlioPrice8 жыл бұрын
+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.
@agcouper8 жыл бұрын
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.
@pranaydubey67828 жыл бұрын
+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.
@lucasvvop7 жыл бұрын
Every language has its pros and cons and can be very powerful if you know how to use it properly.
@tjalferes5 жыл бұрын
11:34
@JamesNewton12 жыл бұрын
Actual talk starts at 10:00... before that it's fluff.
@thattechguy13987 жыл бұрын
Well I watched the whole video to find out that his friend is fine.