The language definition for JavaScript doesn't permit you to do the things you would want to do to make things like style setting fast. Normally in a strongly typed language the JIT would know it could turn a elem.[string] = string assignment into direct code...
-
-
Replying to @cmuratori @fenomas and
... but in JavaScript, it has no idea what that line means, because it doesn't even know what "elem" is. So the JITs have to resort to heroics where they try to analyze the code to figure out what can be safely turned into fast operations, and what can't.
1 reply 0 retweets 0 likes -
Replying to @cmuratori @fenomas and
A sane scripting language knows this and designs in the minimal amount of "typing" necessary to ensure that you can still have easy-to-read things that a user types, but that the compiler can know definitively what they do. JavaScript fails completely here.
1 reply 0 retweets 5 likes -
Replying to @cmuratori @fenomas and
Normally you'd just be like "yeah, it's a rookie mistake, it happens". Kinda like with HTML and CSS. But sadly, HTML/CSS/JS, despite all three being rookie mistakes across the board, ended up running the top of the entire world's software stack. So that's where we're at :(
0 replies 0 retweets 7 likes -
This Tweet is unavailable.
-
Replying to @fenomas @NoHatCoder and
Sigh. Since apparently nobody knows how this stuff works, I will go grab a performance capture to demonstrate :(
1 reply 0 retweets 2 likes -
Replying to @cmuratori @fenomas and
So from Chrome's perf recorder, the "recalc" time is 50ms after the script runs. If I take the script and do the optimized version, it takes ~50ms as well, so it's 50ms/50ms. If I turn up the number of things it sets, and make it set them poorly, it's 423ms/50ms.
1 reply 0 retweets 2 likes -
Replying to @cmuratori @fenomas and
And if I try to regress it all the way back to the original code that I started with, although I'm not 100% sure exactly what that looked like, it takes 2.67s/50ms. So at least as far as I can tell, the recalc time is always constant.
1 reply 0 retweets 0 likes -
Replying to @cmuratori @fenomas and
It's just how inefficiently you go about setting things. If you set a bunch of styles and look up elements poorly, and/or make function calls instead of not, etc., you can make the JavaScript take longer and longer but it's not because of the recalc.
2 replies 0 retweets 1 like -
Replying to @cmuratori @fenomas and
That said, in capturing those perfs I did see a disturbing amount of variability across runs of the same page/script in Chrome :( So one significant caveat here might be that I guess I don't know if Chrome has some bad bugs in here that are making these perf results suspect?
1 reply 0 retweets 0 likes
I'm on a local machine and it's 1 image, 1 HTML file, and 1 js file, so I would not have expected there to be a lot of variability in the perf capture but there was. Especially in the part that happened before the script actually executed, which isn't relevant here, but still.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.