facebook / hermes

A JavaScript engine optimized for running React Native.
https://hermesengine.dev/
MIT License
9.77k stars 627 forks source link

Transpiler / bundler example or documentation? #1145

Open evelant opened 1 year ago

evelant commented 1 year ago

Problem

I wanted to run some benchmarks on v8 and hermes to compare proxy performance because I'm having perf issues on react-native Android using mobx, which relies heavily on proxies. I wasn't able to figure out a bundler/transpiler configuration that was able to emit code that would run on hermes.

Bun and esbuild can't downlevel features low enough to accommodate hermes lack of class, let, const, async, etc. I tried rollup + babel but bundling to a single file with rollup in IIFE mode appears to result in globals like setTimeout being unavailable. I tried metro, but trying to use it outside of react native I couldn't get it configured to emit a bundle properly.

Solution

It would be great if the hermes repo included an example with a bundler configuration that can transpile modern TS down to a level that it can be run with the hermes binary. Either that or a short documentation addition detailing which tools can work and what configuration they need.

This would make it a lot easier to use hermes outside of react native.

Additional Context

tmikov commented 1 year ago

Hermes supports "async" functions, no need to transpile those. I also don't understand how IIFE can prevent globals from being available. In any case, I will take a look and come up with a Babel config for this.

On the topic of JS proxy. Proxy is extremely slow and very complex. We recommend against it under all circumstances.

evelant commented 1 year ago

Unfortunately my app is completely tied to mobx at this point. I can't avoid proxies. I was hoping to do some performance comparison of proxies between hermes and other JS engines that might help reveal areas for perf improvments of hermes' proxy implementation.

tmikov commented 1 year ago

@evelant I suspect the Hermes proxy implementation has similar performance to JSC and v8 in jitless mode (although if it doesn't, we will definitely work to match their performance).

A comparison of the Hermes interpreter against a speculating JIT will not produce meaningful results - the JIT will clearly be much faster.