New low level JavaScript interpreter to boost WebKit performance more than 200%

Posted:
in macOS edited January 2014


Apple's WebKit JavaScriptCore is now a "triple tier virtual machine," offering the potential for 2-2.5 times faster JavaScript performance in Safari.



Recent changes in Apple's WebKit open source project (used by Safari on OS X and iOS, and to power a wide variety of other browsers) include the incorporation of the efficient new LLInt (Low Level Interpreter), which is now used by JavaScriptCore (JSC) to attempt executing code before passing it to the standard interpreters, either the bytecode virtual machine or the JIT (Just In Time complier) which builds native machine code on the fly.



"JSC will now will start by executing code in LLInt and will only tier up to the old JIT after the code is proven hot," a change report on the new interpreter describes.



"LLInt is written in a modified form of our macro assembly. This new macro assembly is compiled by an offline assembler (see offlineasm), which implements many modern conveniences such as a Turing-complete CPS-based macro language and direct access to relevant C++ type information (basically offsets of fields and sizes of structs/classes)."



The new interpreter "is 2-2.5x faster than our old interpreter on SunSpider, V8, and Kraken [benchmarks]," the report states. "With triple-tiering turned on [to allow the LLInt to interpret code], we're neutral on SunSpider, V8, and Kraken, but appear to get a double-digit improvement on real-world websites due to a huge reduction in the amount of JIT'ing."



JavaScript performance in web browsers is a primary focus for optimization, as the faster and more efficiently code can be executed, the more fluid animations can run and the more sophisticated and responsive cross platform web applications can be.



The LLInt enhancements to JavaScriptCore appear to have been contributed by Filip Pizlo, who joined WebKit as a reviewer in December after acting as a "major contributor" to improvements to the JavaScriptCore JIT and Garbage Collector. Pizlo filed a bug report in January noting that "JSC should be a triple-tier VM," and subsequently solved the issue by the end of February.



The new changes to JavaScriptCore will take some time to make it into the mainstream version of Safari, following similar WebKit enhancements of previous years. Enhancements in Apple's next release of Safari 5.2 have been profiled in reports describing its new user interface and sharing enhancements and new privacy settings and website alert features.











Improvements to Nitro in JavaScriptCore



In 2008, WebKit announced a rewriting of JavaScriptCore as a direct-dispatch register based, high-level bytecode virtual machine originally named SquirrelFish. It compiled JavaScript into native machine code. The project was later enhanced to gain the codename SquirrelFish Extreme.











In 2009, Apple applied the enhancements to Safari 4 under the brand "Nitro," noting that the new implementation could run JavaScript up to 4.5 times faster.



The next year, it subsequently released new SquirrelFish Extreme enhancements in Safari 5, boosting JavaScript performance on the Mac another 30 percent over the previous Safari 4.



Last year, the company added Nitro to mobile Safari in iOS 4.3, boosting JavaScript performance by 200 percent on Apple's mobile devices. However, a minor controversy ensued after it was found that iOS only used Nitro to accelerate web apps running in Safari; this resulted in a significant speed penalty when full screen web apps were saved to the home screen.



In iOS 5, Apple solved the security issues that prevented earlier releases from running full screen web apps using Nitro, although security measures still prevent apps that use UIWebView to present a web view from invoking Nitro.



Google's JavaScript competitors



Other WebKit browsers don't necessarily use JavaScript Core. Google's Chrome uses its own competing V8 JavaScript engine, for example.



V8 seeks to enhance performance by compiling JavaScript to native code before executing it. It was developed by a team led by Lars Bak, the programmer who developed Sun's Java ME virtual machine. After Oracle acquired Sun, it filed suit against Google for infringing patents related to virtual machines, including a patent filed by Bak while working for Sun.



JavaScript, which is related to Java in name only, was originally developed at Netscape as a way to add programatic interactivity to web pages (it was previously named LiveScript). JavaScript has since become a widely established open standard, sometimes referred to as ECMAScript, after the standards body that now manages it as a specification. Microsoft formerly supported its own vbscript, but has since backed interoperability on the web through the common use of JavaScript.



Google has recently sought to replace JavaScript with its own new web programming language named Dart (originally Dash), which was codeveloped by Bak. Apple, Mozilla and Microsoft have all opposed Google's plans to replace JavaScript with its own new language, preferring instead to continually improve upon JavaScript.



Mozilla's Brendan Eich, who developed the original JavaScript at Netscape, recently wrote, "I guarantee you that Apple and Microsoft (and Opera and Mozilla, but the first two are enough) will never embed the Dart VM," adding, "Google's approach with Dart is thus pretty much all wrong and doomed to leave Dart in excellent yet non-standardized and non-interoperable implementation status," and musing, "could Google, unlike Microsoft ten or so years ago, prevail? Only by becoming the new monopoly power on the web. We know how that story ends."



In a discussion about Dart in December, Apple's Oliver Hunt wrote, "Adding direct and exposed support for a non-standard language is hostile to the open-web by skipping any form "consensus" driven language development that might happen, and foisting whatever language we want on the web instead. This implicitly puts any browser that supports additional proprietary extensions in the same position as a browser supporting something like vbscript, and has the same effect: breaking the open web by making content that only works effectively in a single product."



Google's efforts to leverage Chrome to push its own preferred technologies rather than open standards has also occured with its own WebM video codec (as opposed to H.264) and a prioritization of Adobe's Flash (over HTML5) for delivering video and interactivity, particularly as a differentiating feature of its Android mobile platform.



[ View article on AppleInsider ]

«13

Comments

  • Reply 1 of 41
    MacProMacPro Posts: 19,727member
    So Safari would be snappier?
  • Reply 2 of 41
    solipsismxsolipsismx Posts: 19,566member
    I worry about these LL interpreters from a security PoV.
  • Reply 3 of 41
    Dan_DilgerDan_Dilger Posts: 1,583member
    Quote:
    Originally Posted by SolipsismX View Post


    1) I worry about these LL interpreters from a security PoV.



    2) Despite WebM ownership and iffy legitimacy it's been a part of Safari for a long time.



    Safari does not support WebM unless you install Google's plugins. Similar to Flash.
  • Reply 4 of 41
    solipsismxsolipsismx Posts: 19,566member
    Quote:
    Originally Posted by Corrections View Post


    Safari does not support WebM unless you install Google's plugins. Similar to Flash.



    Mea culpa! I know I didn't have any Google plugins installed but then I realized I have Perian installed.
  • Reply 5 of 41
    wizard69wizard69 Posts: 13,377member
    Quote:
    Originally Posted by digitalclips View Post


    So Safari would be snappier?



    Hopefully this works just as well on ARM as it does on i86. Javascript is a big deal and performance is always an issue.



    I find it funny that they indicated that they get good results by limiting JIT because a year or two a go JIT compiling was all the rage. Talk about rapid evolution.
  • Reply 6 of 41
    MacProMacPro Posts: 19,727member
    I know this is off topic but I say this purely in the context of the evaluation of Apple's latest offerings ... ... I just spent the day using Windows 8. OMG! ... Lipstick on a pig would be an understatement. Underneath those tiles is nothing but ... good old Windows dumbed down. I am truly shocked how horrible it is.



    Apple is going to be a Trillion dollar company for sure!
  • Reply 7 of 41
    jpellinojpellino Posts: 699member
    Quote:
    Originally Posted by digitalclips View Post


    I know this is off topic but I say this purely in the context of the evaluation of Apple's latest offerings ... ... I just spent the day using Windows 8. OMG! ... Lipstick on a pig would be an understatement. Underneath those tiles is nothing but ... good old Windows dumbed down. I am truly shocked how horrible it is.



    Apple is going to be a Trillion dollar company for sure!



    Yeah, our FreshStart machines with 2000 still do everything we ever asked them too and no one complains because the start menu isn't flashy. And except for having to remind myself which version of Windows I'm peering at based on eye candy, I can't remember the last time I said "I'm so glad the new Windows does [fill in your favorite whizzy thing]"
  • Reply 8 of 41
    MacProMacPro Posts: 19,727member
    Quote:
    Originally Posted by jpellino View Post


    Yeah, our FreshStart machines with 2000 still do everything we ever asked them too and no one complains because the start menu isn't flashy. And except for having to remind myself which version of Windows I'm peering at based on eye candy, I can't remember the last time I said "I'm so glad the new Windows does [fill in your favorite whizzy thing]"



    I was honestly expecting something new! I am totally amazed they think they can pass off the same old Windows as something new with a different Start Menu changed into these tiles and side bars. Once past that in fact it is far worse than 7 which I actually don't mind all that much when I have to use it.
  • Reply 9 of 41
    rgfsteedrgfsteed Posts: 20member
    Just to be clear, 2x the speed is a 100% increase, not 200%. Still not bad though, so I look forward to getting Mountain Lion.
  • Reply 10 of 41
    malaxmalax Posts: 1,598member
    "JSC will now will start by executing code in LLInt and will only tier up to the old JIT after the code is proven hot," a change report on the new interpreter describes.



    "LLInt is written in a modified form of our macro assembly. This new macro assembly is compiled by an offline assembler (see offlineasm), which implements many modern conveniences such as a Turing-complete CPS-based macro language and direct access to relevant C++ type information (basically offsets of fields and sizes of structs/classes)."





    uhh, ok thanks for that useful info. Glad the old JIT won't be getting any cold code.
  • Reply 11 of 41
    wizard69wizard69 Posts: 13,377member
    Quote:
    Originally Posted by rgfsteed View Post


    Just to be clear, 2x the speed is a 100% increase, not 200%. Still not bad though, so I look forward to getting Mountain Lion.



    If not it will most likely be in Safari 5.3. Either way it does look like a very nice improvement.
  • Reply 12 of 41
    mjtomlinmjtomlin Posts: 2,673member
    Wow! Google is really starting to look and act like Microsoft of yesteryear. So much for the open web, when all the technology Google wants to use is their own proprietary stuff. Yes, they may freely license and open source it, but that doesn't mean at some point in the future they won't close it up, just as they're beginning to do with Android now.



    Unfortunately for Google, I think everyone in the industry still remembers the toll Microsoft took on the web after the release of Internet Explorer 6. It's been over ten years and we're still feeling the hurt from it.



    Anyway, It'll be nice if Apple would finally give us a non-Google maps app for iOS, then I can totally be rid of their services... well except YouTube.
  • Reply 13 of 41
    ljocampoljocampo Posts: 657member
    Quote:
    Originally Posted by AppleInsider View Post


    JavaScript performance in web browsers is a primary focus for optimization, as the faster and more efficiently code can be executed, the more fluid animations can run and the more sophisticated and responsive cross platform web applications can be.



    Which means far better and faster rendered blinking ads to be "in your face." That makes it possible for AI to increase the amount of them too!



    I can't wait. I'm trilled!! /s
  • Reply 14 of 41
    mdriftmeyermdriftmeyer Posts: 7,503member
    Pizlo's Info: http://www.filpizlo.com/research.html



    FYI: The major company he works for is Apple.



    He's a Ph.D candidate in Computer Science from Purdue University.
  • Reply 15 of 41
    mdriftmeyermdriftmeyer Posts: 7,503member
    Quote:
    Originally Posted by ljocampo View Post


    Which means far better and faster rendered blinking ads to be "in your face." That makes it possible for AI to increase the amount of them too!



    I can't wait. I'm trilled!! /s



    It means WebGL and WebCL performance gains considerably meaning a faster demise to Flash Games.
  • Reply 16 of 41
    mdriftmeyermdriftmeyer Posts: 7,503member
    Quote:
    Originally Posted by wizard69 View Post


    If not it will most likely be in Safari 5.3. Either way it does look like a very nice improvement.



    Test it out in the Nightly.
  • Reply 17 of 41
    foljsfoljs Posts: 390member
    Quote:
    Originally Posted by malax View Post


    "JSC will now will start by executing code in LLInt and will only tier up to the old JIT after the code is proven hot," a change report on the new interpreter describes.



    "LLInt is written in a modified form of our macro assembly. This new macro assembly is compiled by an offline assembler (see offlineasm), which implements many modern conveniences such as a Turing-complete CPS-based macro language and direct access to relevant C++ type information (basically offsets of fields and sizes of structs/classes)."





    uhh, ok thanks for that useful info. Glad the old JIT won't be getting any cold code.



    Hehe, let me translate that for you:



    The JIT is a component of the Javascript engine that can change code so it runs much faster.



    But the change takes some time.



    So, if you are gonna run something only once, it could actually take more time to change it to run faster AND then run it, than to just run it as it was.



    So, the new engine is smart enough, to only try to make code faster if it is known that it will be run many times (ie it is "hot").



    An analogy, if you are still confused:



    A JIT is like a pit-stop for your racing car.



    The pit-stop can make some changes that will make the car run faster, but it takes some time, during which you'll be off the race.



    So, it only makes sense to stop there if there are lots of rounds still to be made, so you can "amortize" the time spend, not if you're one round before the end of the race.
  • Reply 18 of 41
    morkymorky Posts: 200member
    It's a shame Apple pays so little attention to Safari on Windows. It feels foreign there. Safari really could have been what Chrome has become.
  • Reply 19 of 41
    solipsismxsolipsismx Posts: 19,566member
    Quote:
    Originally Posted by Morky View Post


    It's a shame Apple pays so little attention to Safari on Windows. It feels foreign there. Safari really could have been what Chrome has become.



    I don't think that was ever Apple's goal. I think (please correct meif wrong) there reason for that was a parallel move to eventually moving the iTunes Store in iTunes to being WebKit based.



    Opening up WebKit was the brilliant move. The most important thing is that WebKit is used on more devices than any other browser engine. No longer will Safari on Apple devices not be supported by the internet at large... though I did come across a government site just last month that would only work in IE or Firefox.
  • Reply 20 of 41
    jragostajragosta Posts: 10,473member
    Quote:
    Originally Posted by SolipsismX View Post


    I don't think that was ever Apple's goal. I think (please correct meif wrong) there reason for that was a parallel move to eventually moving the iTunes Store in iTunes to being WebKit based.



    Opening up WebKit was the brilliant move. The most important thing is that WebKit is used on more devices than any other browser engine. No longer will Safari on Apple devices not be supported by the internet at large... though I did come across a government site just last month that would only work in IE or Firefox.



    Exactly. Apple benefits from being part of open standards in things like this. Bragging rights to "our browser is used more than your browser" just isn't that big a deal. But being able to say that "our browser recognizes the entire Internet" is important.



    My bank was one of the last hold-outs I've seen. Until last month, I had to use my Windows computer to access some functions of the bank's site, but they just updated it to work on Macs, as well.
Sign In or Register to comment.