276 points · by Bootvis · 8y ago · 124 comments
I worked very hard on pulling the same trick at Sony. We'd made Vegas scriptable, and, once it was part of Bapco's Sysmark, we received immense support from chip vendors. Machines, engineers, tools, instructions added to instruction sets... It was a nutty time.
Of course, the biggest wins worked everywhere, like the 6755399441055744 single precision rounding trick, or the use of memory mapped file regions to cache the rendering tree. Still, becoming part of a performance benchmark is a great way to get attention.
http://benediktmeurer.de/2016/12/16/the-truth-about-traditio...
This is when Chrome on Android finally started to turn a corner, they've done a fantastic job. JS perf has increased 50% from 2016 to 2018 in Chrome/Android. Sadly Android is still hamstrung by extremely mediocre Qualcomm SoCs but they've made huge strides on the software side.
Not talking about Go language.
https://www.destroyallsoftware.com/talks/the-birth-and-death...
EDIT: before people accuse me of making a false dichotomy: I acknowledge that there are other uses for computers, but am unable to think of any others where the increased resource consumption would be worth it. Another thing: cell phones, the battery would drain much more quickly if everything were a webapp. Perhaps video game consoles will switch to such a JIT, though...
Not exactly Javascript but running untrusted code in a safe language in the kernel can give already performance improvements for some workloads due to avoiding system call overhead. It will be interesting to see where this goes in the future.
https://en.wikipedia.org/wiki/Jazelle
I would not be surprised if they come up with a way of directly executing WASM or such. (And then the possibilities for security exploits become a lot more interesting...)
I’m also not sure if that’s a “win” in general. Dynamic languages used doubles since forever now and to me, either A) cpu makers sleep for too long, B) js is such a historical mess that fixing it in hw is reasonable now.
It is interesting how e.g. LuaJIT may benefit from that, but unfortunately it is [formally] unavailable on appstore because of licensing restrictions. As are non-apple fast js engines.
As for other languages that use Doubles, this instruction isn't for general-purpose Doubles. CPUs already handle those. This instruction specifically implements the exact semantics that JavaScript wants. Now, maybe some other dynamic languages would want the same semantics when converting Doubles to ints, I don't know. But it's by no means a given that they would. Also, most languages don't use Doubles for all numeric types anyway.
And as a nail in the coffin for this nonsense: javascriptcore does not use or even emit this instruction: https://mobile.twitter.com/saambarati/status/104920213252247...
I disagree. My use cases involve loading, processing, rendering, and saving point clouds with millions to billions of points. For precision and file size reasons, coordinates are stored as 3 x int32 instead of 3 x float or 3 x double. Every time I load the points from disk I have to convert them to floats for rendering, or doubles for processing. Vice-versa for storing the processed results to disk.
Just because you don't need it, doesn't mean nobody needs it.
I get storing them as float instead of double but into instead of float for size/precision doesn't really make sense to me. A float is 32 bits, so will be the same size as an int(32). If it's precision you're worried about,you're going to lose the precision as soon as you convert it from an int to a float to use.
Integers on the other hand can be used to represent coordinates in a fixed precision. E.g. if you want to store coordinates in milimeter precision, you multiply your double precision meter coordinates by 1000, and then cast the resulting coordinate to 32 bit integers.
> If it's precision you're worried about,you're going to lose the precision as soon as you convert it from an int to a float to use.
Yes, that is why you convert ints to doubles for processing and only use floats for tasks where limited accuracy is okay, e.g. rendering.
This isn’t “conversion doesn’t need to be fast”, this is “conversion is so fast already that that won’t be your bottleneck”.
Even if it was slow, given what you are describing I would assume that you performance would be bottlenecked on IO even with a pure software floating point conversion.
In this case I’d trust Filip more :)
I mean I suppose it makes sense for them to do that, especially if the performance benefits are as huge as outlined in this tweet, but damn it feels dirty.
I assume the reason for this is that in JS, as far as I know, all numbers are stored as floats right? So you keep casting everywhere when you need an integer? I assumed that JS implementations where a bit more clever and kept them as ints whenever possible but maybe it's not as simple as I had imagined.
In reality the big win from this instruction is not performance, it’s code size.
So no, this instruction does not explain 40% perf improvement. It’s very easy to see why: for it to be a 40% (or any significant %) win your code would already have to be spending at least 40% of the time doing just double to int conversions. Not even micro benchmarks manage that level of insanity.
Anyone can point to where it is used?
This isn't something a JS developer uses. It's something as JS VM/engine developer uses to make JS faster on that platform in general.
"I took a quick look at Speedometer 2.0 and it seemed to be driven by the speed of the browser cache implementation, as in how much was explicitly in memory, what poked the file system, how async was implemented. Not CPU bound."
2018: I never thought I'd be walking around with a full Symbolics Lisp Machine in my pocket.
However, I like to think about it as carrying a Xerox Workstation or an IBM mainframe on my pocket, as both iOS and Android trace back to them.
Smalltalk, Lisp, Mesa/Cedar, bytecode environments with micro-coded CPUs, or JIT services on kernel with portable executables (IBM/Unisys).
Heck let’s propose the JPU (JavaScript Processing Unit) for server-side codes.
1. https://webkit.org/blog/5852/introducing-the-b3-jit-compiler...
> The FTL JIT was designed as a marriage between a high-level optimizing compiler that inferred types and optimized away type checks
Why not just use types in your language? It's not that difficult and makes a massive performance increase.
What you’re essentially asking is: why are you supporting JavaScript?
Also a lot of those optimizations occur in jits for statically types languages. Because many of the optimizations are functionally equivalent to “static” language ideas like devirtualisation and the like.
SPECint2006 -- 36.93 --> 44.92 is about 20% better
Speedometer2 -- 90 --> 125 is 38% better
That is nearly 2x what SPECint would predict. (It's also not changes in Mobile Safari / iOS 12 because every device benchmarked was on the same version of iOS 12).
[1]: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc....
Did someone say ARM is RISC?
So risc has slowly become analogous to “more registers, orthogonal instruction set, not x86”
Load/store are still always separate instructions, and instruction length is fixed — that's RISC enough. (But the distinction is not super meaningful these days anyway.)
1. Click to get to jeff's tweet from hacker news.
2. Click Gregs tweet.
3. Click back (works and we get to jeffs tweet)
4. Successive back clicks never get to Hacker News.
Only Apple had the #courage.
Apple designed the chip, and ARM designed the platform and instructions for them to build with.
Apple designs the chips:
https://en.wikipedia.org/wiki/Apple-designed_processors
Specifically,
Apple has an ARM "architectural license", which is for
companies "designing their own CPU cores using the ARM
instruction sets. These cores must comply fully with the
ARM architecture. Companies that have designed cores that
implement an ARM architecture include Apple, AppliedMicro,
Broadcom, Cavium (now: Marvell), Nvidia, Qualcomm, and
Samsung Electronics.
https://en.wikipedia.org/wiki/ARM_architecture#LicensingARM designed that JS-optimized instruction. Apple just follows (and it has to) ARM specification in Apple’s own way.
Don’t confuse between ISA design and its chip implementation design.
Let's not exaggerate nor underestimate the fool's errand of replacing a ubiquitous language.
All the things we could be doing and we're making CPU improvements for the flaming pile of hot trash that is JS? Why?
Even many 'native' apps, mobile or desktop (electron) are written in javascript, and how much of your time do you spend in your browser or electron apps every day? Think vscode, atom, Spotify, Slack, facebook, reddit, twitter, ...
I would expect that the only actual change here is the final rounding and register store which is not significant. Those are already things that have to happen.