10 ms·
Why iPhone Xs performance on JavaScript is so good
- faitswulff 8y ago@steipete puts it pretty well: JavaScript really made it. We now tweak CPUs to make it faster. https://twitter.com/steipete/status/1047415826083729408 https://twitter.com/steipete/status/1047415826083729408
- userbinator 8y agoARM did something similar with Java before: https://en.wikipedia.org/wiki/Jazelle 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...)
- naphthalene 8y agoWasn't ARM's choice directly related to (or maybe influenced by) Android though?
- nonsince 8y agoThe only thing they could do for Wasm would be to allow sub-process-granularity hardware memory access virtualisation and easily-enforceable float rounding modes afaik
- tzs 8y agoThat was a trick Dave Fotland used in the '80s to make his Go program, "Many Faces of Go", faster. He donated some key code from his evaluation function to SPEC and they used it as one of the parts in the SPEC integer CPU benchmarks. CPU makers tweaked CPUs to do well on those benchmarks, and hence on his code.
- acemarke 8y agoI had to read that comment a couple times before I realized you were referring to the board game and not the programming language :)
- kbenson 8y agoThat's a wonderful bit of social engineering.
- codinghorror 8y agoI highly recommend this article in that same vein http://benediktmeurer.de/2016/12/16/the-truth-about-traditional-javascript-benchmarks/ 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.
- chaboud 8y agoI've talked with him about those days... Though I haven't chatted with him about Go since AlphaGo flipped the whole world over. 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.
- nashashmi 8y agoI was confused by the words "Go Program" "in the '80s" in one sentence. OP is talking here about the Go board game played by a computer AI. Not talking about Go language.
- ihuman 8y ago"The Birth and Death of Javascript" becomes more and more real https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript https://www.destroyallsoftware.com/talks/the-birth-and-death...
- enraged_camel 8y agoI like the part about the Bay Area being a radioactive wasteland. :)
- Analemma_ 8y agoTechnically, he only said it was an "Exclusion Zone", so it could refer to real estate prices in the 2035 Bay Area for non-quadrillionaires.
- RightMillennial 8y agoFallout: New Francisco
- ndesaulniers 8y agoWe're firmly within NCR territory here.
- IgorPartola 8y agoThe Hobologists send their regards.
- earenndil 8y agoI still don't buy it. Javascript might buy a 4% performance improvement, but the increased resource usage makes that impractical for most scenarios. For server use, the increased wear makes it cheaper to buy more computers and have them last longer. For application use, performance is not relevant enough to make it interesting. So really the only possible application is video games. 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...
- mortenjorck 8y agoIn retrospect, it’s almost surprising that there was never a push for hardware acceleration of common JavaScript operations.
- wruza 8y agoWhy? It is not special in any way. It is area in which you can be special only in special olympics sense. The new instruction doesn’t make anything new, it is just different and serves no purpose for 99.9% of users.
- djrogers 8y ago100% of users of mobile devices use JavaScript. 98% of them use it heavily in their web browsers. To ignore it, or try to pass it off as insignificant, is folly.
- wruza 8y agoOh, words go playing. Who uses that modulo 2^32 thing heavily in their browsers? Folly is wasting world’s resources on ineffective crappy implementation of unused features. Obviously it seems reasonable to fix hw. If I were Apple, I wouldn’t even think to reason with js socium.
- millstone 8y agoALU ops are cheap, interconnects are expensive. Curse JS for scatter-gather, not for its FCVTZS details. (Though now I can't explain the magnitude of the win...fine, curse JS for both.)
- wruza 8y agoApple now tweaks cpus to make their js engine faster. This doesn’t sound as cool, but is more true. 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.
- eridius 8y agoAny JS engine on an ARMv8.3 chip could benefit from this instruction, not just Apple's JS engine. Sure you can't put other JS engines on an iPhone (at least not without jailbreaking), but this says ARMv8.3 adds it, not "Apple's specific CPU", though I have no idea if there are any other ARMv8.3 chips at the moment. 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.
- thought_alarm 8y ago2008: I never thought I'd be walking around with a full Unix machine in my pocket. 2018: I never thought I'd be walking around with a full Symbolics Lisp Machine in my pocket.
- blihp 8y ago2028: Why does battery life still suck?
- peter_tonoli 8y agoRemindMe! 10 years
- xj9 8y agothere's a lisp phone now? where can i buy one?
- pjmlp 8y agoThe Web still needs to catch up with some of Symbolics Lisp Machine development environment features though. 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).
- wruza 8y agoAs if double to int/ptr was js-specific.
- wtfrmyinitials 8y agoThe javascript specific bit is that errors and out-of-range values are handled according to js semantics
- angelsl 8y agoNo, but this does it the way JavaScript wants it. FCVTZS has always been therr. FJCVTZS[1] is new. [1]: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0801g/hko1477562192868.html http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.... Did someone say ARM is RISC?
- userbinator 8y agoIndeed, it could be said that ARM not being pure RISC is what keeps it competitive with x86. I wonder how long it'll be before x86 also gets a similar set of instructions...
- Dylan16807 8y agoThe instruction is just specifying particular semantics, that doesn't really disqualify it from being RISC. The instruction doesn't do more than the baseline variant.
- olliej 8y agoThe traditional (eg mips) definition of risc was that the cpu should not hide how it operated - in essence, the compiler was required to schedule operations efficiently itself for both performance and correctness. That’s why MIPS and others have things like branch delay slots. It turns out that that is a terrible idea - it means binaries are tied to a specific micro architecture, let alone a separate implementation of the same ISA. Traditional risc also did not support floating point or integer division (both in software), except again software is necessarily slower than a hardware pipeline. So risc has slowly become analogous to “more registers, orthogonal instruction set, not x86”
- im3w1l 8y agoIf there are any twitter devs here, clicking Greg Parker's tweet breaks the back button for me.
- zenexer 8y agoWhat browser? Working in latest stable Chrome on Windows.
- im3w1l 8y agoDetailed steps: Firefox on windows. 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.
- Operyl 8y agoCan’t reproduce on Safari here.
- forrestthewoods 8y agoHardware instructions created to handle JavaScript specifics makes me so very sad. What a terrible state of affairs.
- umanwizard 8y agoWhy?
- FridgeSeal 8y agoBecause, despite our papering over of some of it's warts, JS is still fundamentally a pretty terrible language; and rather than everyone trying to make it be better, shouldn't we devote time and hardware efforts like this to either language agnostic improvements, or to languages that are better designed?
- wild_preference 8y agoWell, it's not terrible nor worse than other dynamically-typed programming languages. And it's one of the few languages with async-everything. Let's not exaggerate nor underestimate the fool's errand of replacing a ubiquitous language.
- FridgeSeal 8y ago> Well, it's not terrible nor worse than other dynamically-typed programming languages. Not better or worse? It's got a type system with holes you could drive truck through, and more arcane edge-cases than a fantasy book of spells. > And it's one of the few languages with async-everything. Just because something is async doesn't make it better or faster, at some point the work has to be done, and for those cases where async does make a difference, pretty much every other language has an async implementation that is either just as good or superior. > Let's not exaggerate nor underestimate the fool's errand of replacing a ubiquitous language. Yeah, I think that horse has bolted, but we can stop making it anymore widespread than it absolutely needs to be.
- blinkingled 8y agoWithout clicking the link i knew this was going to be Jeff Atwood - something about iPhone's JS performance seems to crack him up perpetually! :) Also see Dan Kaminsky's reply - "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."
- xrd 8y agoThat's pretty serious, right? Changes the entire conversation if this is not truly improving execution speed?
- blinkingled 8y agoYes - and if it does it doesn't matter for this particular benchmark which isn't CPU bound.
- codinghorror 8y agoJS perf has tightly tracked single threaded CPU perf for a long, long time -- as long as I can remember. That said, it is certainly possible memory speed is also a factor, see https://www.anandtech.com/show/13392/the-iphone-xs-xs-max-review-unveiling-the-silicon-secrets/3 https://www.anandtech.com/show/13392/the-iphone-xs-xs-max-re...
- zbjornson 8y agohttps://developer.arm.com/docs/100069/latest/a64-floating-point-instructions/fjcvtzs https://developer.arm.com/docs/100069/latest/a64-floating-po... (FJCVTZS: Floating-point Javascript Convert to Signed fixed-point, rounding toward Zero) is the instruction they're talking about. One main difference (vs FCVTZS) is that it sets the Z flag depending on whether the conversion was exact, and it's mod 2^32 on overflow.
- wruza 8y agoLet’s count how many of js users did know about this “feature” before this thread (those who don’t understand what it “does” count too). Anyone can point to where it is used?
- untog 8y agoThis isn't something a JS developer uses. It's something the CPU uses with JS someone wrote
- kbenson 8y agoA less confusing way to put it might be this: 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.
- mikeash 8y agoIt’s an implicit part of every bitwise operation in JS.
- deleted 8y ago[deleted]
- kbumsik 8y agoThis explains everything. BTW does float=>int conversion a lot in JS other than the implicit 32bit bitwise operation?
- 8y ago
- jayd16 8y agoFixing javascript with hardware? Its not exactly genius but it seems worth it. Only Apple had the #courage.
- kbenson 8y agoApple just has a shorter distance between CPU engineering and software engineering departments, which allows them to coordinate more and quicker, and bring something like this to market faster. It's not courage, it's reading the writing on the wall and being able to cut through the red tape faster.
- jayd16 8y agoIts just a joke about baking the drawbacks of javascript into the hardware. Its a good change that's probably overdue at this point.
- kbumsik 8y agoARM did it, not Apple.
- JohnBooty 8y agoApple did it, not ARM. Apple designs the chips: https://en.wikipedia.org/wiki/Apple-designed_processors 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#Licensing https://en.wikipedia.org/wiki/ARM_architecture#Licensing
- etaoins 8y agoThis is an instruction specified in the ARMv8.3‑A instruction set. It was specified and designed by ARM, not Apple. Apple is merely the first to ship silicon implementing v8.3-A.
- hden 8y agoSo Apple has its own browser, its own JIT compiler(1), which emits its own instruction sets, which then run own its own CPUs. Heck let’s propose the JPU (JavaScript Processing Unit) for server-side codes. 1. https://webkit.org/blog/5852/introducing-the-b3-jit-compiler/ https://webkit.org/blog/5852/introducing-the-b3-jit-compiler...
- ridiculous_fish 8y agoImagine if Apple had its own operating system running its own static compiler!
- cm2187 8y agoWith the end of Moore’s law, that may be the way forward, making cpus with more of the software implemented in hardware.
- exabrial 8y agoWhat I find most interesting about that link is this: > 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.
- olliej 8y agoBecause JavaScript does not have types? 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.
- jjgod 8y agoJeff Atwood/DHH’s conclusion regarding Speedometer 2 is not completely true according to Filip Pizło (https://webkit.org/blog/author/fpizlo/ https://webkit.org/blog/author/fpizlo/): https://twitter.com/filpizlo/status/1049132270773198848 https://twitter.com/filpizlo/status/1049132270773198848 In this case I’d trust Filip more :)
- codinghorror 8y agoAs I said in my reply to that, it could also be in combination with the much faster memory / caches on A12 -- see https://www.anandtech.com/show/13392/the-iphone-xs-xs-max-review-unveiling-the-silicon-secrets/3 https://www.anandtech.com/show/13392/the-iphone-xs-xs-max-re...
- fredfoobar 8y agoWanting JavaScript to win is like wanting Donald Trump to win.
- sercand 8y agoAccording to https://www.anandtech.com/show/13392/the-iphone-xs-xs-max-review-unveiling-the-silicon-secrets/4 https://www.anandtech.com/show/13392/the-iphone-xs-xs-max-re... reason is new memory subsystem. The new chip is not just fast at Speedometer 2 but %40 faster almost all at other benchmarks. Also, all iPhone devices are fast with iOS 12 JavascriptCore.
- codinghorror 8y agoIt's not 40% faster at "almost all other benchmarks". In Geekbench 4 single core, it's about 15% faster, and in many other benchmarks about the same. That's why the official guidance from Apple is that the XS should be 15% faster. Having seen the other low level benchmarks, I was really surprised when I saw the Speedometer results..
- codinghorror 8y agoPer https://images.anandtech.com/doci/13392/SPEC2006-eff_575px.png https://images.anandtech.com/doci/13392/SPEC2006-eff_575px.p... 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).
- vbezhenar 8y agoI think that it's inevitable path of processor evolution. When it's hard to increase performance, processors will include more useful bits of functionality for popular runtimes.
- olliej 8y agoThis instruction cannot result in a significant performance improvement for any js code that isn’t absolutely perf bound on just converting floats to integers. If your code is successfully making that your bottleneck your code has problems. None of the major benchmarks (I can’t even think of micro benchmarks that could really achieve this) are spending significant time doing double to integer conversions. 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/1049202132522479616 https://mobile.twitter.com/saambarati/status/104920213252247...
- mschuetz 8y ago> If your code is successfully making that your bottleneck your code has problems. 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.
- titzer 8y agoYou should consider using WebAssembly if you process so many numbers.
- mschuetz 8y agoJavascript is surprisingly fast at processing that many numbers, using TypedArrays. You just had to avoid DataView up until now but the V8 team recently fixed the performance of DataView so it should have similar performance as TypedArray access and therefore be around 10x faster in future versions of chrome.
- kbumsik 8y agoAlthough they are fast, TypedArrays and DataView only deal with setting/getting data from a buffer. They are totally unrelated to numerical calculations mentioned in OP.
- TalentedIndia 8y agoNow that you’re finally getting used to iOS 12’s new Shortcuts app, here comes Scriptable, a new automation app that runs JavaScript. It can make powerful and deep connections with your iPhone or iPad — working with the Files app, for example, or Reminders.Well, maybe you know how to program JavaScript. Scriptable lets you take your code, and integrate it with iOS. You can make your own scripts and use them to automate iOS.
- nikkwong 8y agoKind of ironic given that safari continues to lag behind in the context of implementing web APIs. Heck, they still don't even support IntersectionObserver, which was introduced in like 2014. I really do share the sentiment of others in calling Safari the new IE; developing for safari on iOS is a total drag. I guess the performance team and specs teams must be compartmentalized :)
- breakingcups 8y agoThis says Webkit doesn't emit these instructions yet: https://bugs.webkit.org/show_bug.cgi?id=184023 https://bugs.webkit.org/show_bug.cgi?id=184023