improve performance • Allow ahead of time compilation to compact bytecode or fast native binaries • Tight native integration through zero-cost calls to C functions 3
the static_h branch of the facebook/hermes repo • Not ready for general use • Many typed features implemented (e.g. unions, classes, generics) • Major improvements to untyped code spec compliance and performance in the works 5
unsound, and do not guarantee that types are correct at runtime • Static Hermes modifies some JS semantics to allow efficient sound typing • New soundly typed code can co-exist and interop with unmodified code 8
Get the cache entry for the read 3. Compare the object with the cache 4. On match, load from cached offset 5. On fail, full dictionary lookup 1. Load from offset 2 1 3 Untyped Typed
Check if i is index-like 3. If it is, attempt to do an indexed load 4. Check if the value is available 5. If any checks fail, full dictionary lookup 1. Check that i is an integer within bounds 2. Load from the array at i 1 5 Untyped Typed
Slow array load from myArr 3. Check if both are numbers 4. If they are, add them 5. If not, fall through to general case (strings, objects, BigInt, etc) 1. Fast load from myVec 2. Fast load from myArr 3. Add the numbers 1 6 Untyped Typed
to where it is called • Depends on the compiler’s ability to statically identify what function is being called, types make this much easier • Enables many other optimizations 3 1
() => number) { this.bar = bar; } }; 3 8 function myFun(){ let fbar = () => 42; return fbar(); } function myFun(){ let f = new Foo(() => 42); let fbar = f.bar; return fbar(); } function myFun(){ return 42; } function myFun(){ let f = { bar: () => 42 }; let fbar = f.bar; return fbar(); } Inlining Object elision Inlining
We use type information to speed up basic operations • Types unlock additional ahead-of-time optimizations like inlining and object elision • These dramatically improve the performance of typed code 4 0
us on GitHub! o https://github.com/facebook/hermes/discussions/categories/static-hermes • For an introduction to Static Hermes, watch Tzvetan's talk at RN EU 2023 o https://youtu.be/q-xKYA0EO-c • For the raytracer benchmark, check out the static_h branch on GitHub o https://github.com/facebook/hermes/tree/static_h/benchmarks/raytracer 4 1