5 ms·
Static Hermes: Compile JavaScript to speed it up 300x (in microbenchmarks)
- jitl 3y agoI wonder how this compares to v8 over the same code. Will v8 get this smart after running the benchmark? I’d test it myself but I’m on an iPhone right now. I wonder if static Hermes will ever end up at break-even or ahead of v8 - especially if doing a lot of FFI in WASM, Hermes might have a better shot at bypassing the memcopy/TextDecoder needed to interop between browser JS strings and WASM utf8 strings in other languages.
- deleted 3y ago[deleted]
- iainmerrick 3y agoIf your runtime is a JS interpreter, on iOS you’re almost always better off just using the OS’s interpreter (JSC). Your app will be smaller, and only the OS is allowed to do JIT so it will be much faster. Even without the JIT restriction, you wouldn’t be able to beat JSC as it’s one of the fastest runtimes out there, pretty much level with V8. Static Hermes sounds like a different prospect, though, if it’s able to use TS annotations to compile to mostly-static native code. That could be great for genuinely high-performance TS code. (Although you wouldn’t want to immediately shackle it to React Native...)
- jamil7 3y agoI believe JIT is disabled in JSC itself on iOS, to take advantage of JIT in JSC you'd have to go through an out-of-process WKWebView instance.
- saagarjha 3y agoJavaScriptCore (the framework) does not use a JIT because it runs in-process. JavaScriptCore (running in a webview) does because it’s out-of-process.
- ricardobeat 3y agoHermes itself is already faster than JSC, which is on par with V8. This just puts it way ahead and probably closer to Swift/Kotlin code, at least in the realm of mobile apps.
- whizzter 3y agoNo, the Hermes interpreter is probably on-par with the JSC-Interpreter if this is a comparison made on iOS React Native apps. JSC-JIT is usually on par or ahead of V8, the iOS JIT restrictions really fudges up results since it's so imperative for JS performance. From what I've seen Kotlin(and Swift prob also) semantics are fare more AOT-compile friendly so they're probably a fair bit ahead (depending on how much you gimp your JS target to mimic Asm.JS/Wasm but most regular JS developers won't write code that way).
- zer0zzz 3y agoThe Hermes interpreter is probably faster than the others because (afaik) it interprets bytecode produced by the hermes frontend parser (which is don’t ahead of time).
- instagary 3y agoWhat data do you have to back up that statement? We've seen the opposite for networking related activities especially when there are 100's of requests that can happen on certain screens. We've tried using Hermes but didn't see any differences other than the app bundle increasing in size.
- andrewstuart 3y agoThere's not much sign of "Static Hermes" on the web. Appears to be a JavaScript compiler from facebook. "Static Hermes is the the next major version of Hermes, still under active development. It enables optional ahead-of-time native compilation of soundly typed JavaScript, using TypeScript or Flow type annotations." I find the AI images in this presentation to be quite distracting for some reason.
- sangelxyz 3y agoIt's the runtime used in React Native.
- zer0zzz 3y agoThe GitHub repo is there. Branch is static_h
- harrygeez 3y agoProbably because it's pretty new. React Native needs to start a JavaScript runtime before it can evaluate its JavaScript code, which is what the application logic is written in, and JS engines are typically not designed to prioritize time-to-interactive metrics and disk usage. Hermes is meant to address some of those concerns and this is probably the next step towards improving those metrics.
- fergie 3y agoThat was an interesting read, but why do Hermes (and React, React Native, etc) still use javascript as a compile target rather than Wasm?
- iainmerrick 3y agoBecause the user’s code is typically written in JavaScript (or TypeScript)? Wasm isn’t a great target for JS.
- circuit10 3y agoHermes is a JavaScript engine, where does being a compile target come into this?
- neftaly 3y agoWasm needs to call into JS to do things like manipulate the DOM and use browser APIs, there's an overhead involved.
- tyingq 3y agoFor an idea of that overhead, see this older article: https://hacks.mozilla.org/2018/10/calls-between-javascript-and-webassembly-are-finally-fast-%f0%9f%8e%89/ https://hacks.mozilla.org/2018/10/calls-between-javascript-a... At first, it sounds really promising, like "wow, all the overhead is fixed". Until you get to the bottom and see: "Currently the only built-ins that we support this for are mostly limited to the math built-ins." So all those terrible "before" graphs mostly still apply today for most DOM interaction and browser APIs. A few more pieces still aren't done for that to work well. This has some pointers to current state: https://stackoverflow.com/questions/62587845/wasm-dom-access-and-reference-types https://stackoverflow.com/questions/62587845/wasm-dom-access...
- conaclos 3y agoSlides of the announcement of Static Hermes are available here [0]. If anyone has the video, this could be great! [0] https://speakerdeck.com/tmikov2023/static-hermes-react-native-eu-2023-announcement https://speakerdeck.com/tmikov2023/static-hermes-react-nativ...