react-nitro-hermes 0.0.1-alpha.8 → 0.0.1-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hermes/CMakeLists.txt +874 -0
- package/hermes/android/HostObjectJniTest.cpp +178 -0
- package/hermes/android/build-logic/build.gradle.kts +31 -0
- package/hermes/android/build-logic/settings.gradle.kts +17 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/helpers/internal/SerializeHermesCompilerPackageJson.kt +33 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/plugins/internal/TestUtilsPlugin.kt +80 -0
- package/hermes/android/build-logic/src/main/kotlin/com/facebook/hermes/tasks/internal/CustomExecTask.kt +46 -0
- package/hermes/android/build-logic/src/main/kotlin/publish.gradle.kts +82 -0
- package/hermes/android/build.gradle.kts +332 -0
- package/hermes/android/cppruntime/build.gradle +72 -0
- package/hermes/android/cppruntime/src/main/AndroidManifest.xml +2 -0
- package/hermes/android/cppruntime/src/main/cpp/CMakeLists.txt +8 -0
- package/hermes/android/cppruntime/src/main/cpp/stub.cpp +12 -0
- package/hermes/android/cross-compile/swift-libicu.patch +13 -0
- package/hermes/android/cross-compile/toolchain-android-arm-api13-gnustl.cmake +13 -0
- package/hermes/android/cross-compile/toolchain-android-arm-api15-gnustl.cmake +14 -0
- package/hermes/android/gradle/libs.versions.toml +30 -0
- package/hermes/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/hermes/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/hermes/android/gradle.properties +3 -0
- package/hermes/android/gradlew +248 -0
- package/hermes/android/gradlew.bat +93 -0
- package/hermes/android/intltest/build.gradle +147 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/CMakeLists.txt +45 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.cpp +68 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.h +44 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogue.java +45 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesEpilogueTestData.java +32 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesInstrumentationTest.java +150 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlAndroidTest.java +147 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesIntlTest262.java +470 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/HermesRuntimeFactory.cpp +73 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.cpp +90 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.h +62 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/JSRuntime.java +155 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.cpp +48 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/MappedFileBuffer.h +36 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoad.cpp +13 -0
- package/hermes/android/intltest/java/com/facebook/hermes/test/OnLoadEpilogue.cpp +13 -0
- package/hermes/android/intltest/src/main/AndroidManifest.xml +2 -0
- package/hermes/android/ios-artifacts/build.gradle.kts +65 -0
- package/hermes/android/settings.gradle.kts +27 -0
- package/hermes/cmake/modules/Hermes.cmake +481 -0
- package/hermes/cmake/modules/Lit.cmake +96 -0
- package/hermes/doc/Branches.md +38 -0
- package/hermes/doc/BuildingAndRunning.md +121 -0
- package/hermes/doc/CodingStandards.md +112 -0
- package/hermes/doc/CrossCompilation.md +79 -0
- package/hermes/doc/Design.md +217 -0
- package/hermes/doc/Emscripten.md +156 -0
- package/hermes/doc/Features.md +143 -0
- package/hermes/doc/GCSafeCoding.md +563 -0
- package/hermes/doc/GenGC.md +300 -0
- package/hermes/doc/Hades.md +344 -0
- package/hermes/doc/HighLevelOptimizations.md +37 -0
- package/hermes/doc/IR.md +1306 -0
- package/hermes/doc/IntlAPIs.md +196 -0
- package/hermes/doc/JIT.md +999 -0
- package/hermes/doc/LazyEvalCompilation.md +84 -0
- package/hermes/doc/MemoryProfilers.md +316 -0
- package/hermes/doc/Modules.md +144 -0
- package/hermes/doc/Optimizer.md +83 -0
- package/hermes/doc/PerfProfiling.md +29 -0
- package/hermes/doc/ProhibitInvoke.md +329 -0
- package/hermes/doc/ReactNative.md +40 -0
- package/hermes/doc/ReactNativeIntegration.md +94 -0
- package/hermes/doc/RegExp.md +24 -0
- package/hermes/doc/SpecIncompat.md +85 -0
- package/hermes/doc/Strings.md +140 -0
- package/hermes/doc/TypedLanguage.md +432 -0
- package/hermes/doc/VM.md +174 -0
- package/hermes/doc/blog/2024-11-09-octane-benchmark-jit-progress.md +17 -0
- package/hermes/doc/blog/2024-12-19-static-hermes-update-dec-2024.md +47 -0
- package/hermes/doc/blog/2024-12-23-compiling-javascript-to-wasm.md +267 -0
- package/hermes/doc/blog/2025-06-09-jsi-runtime-data-apis.md +23 -0
- package/hermes/doc/blog/2025-07-15-static-h-performance-june-2025.md +18 -0
- package/hermes/doc/blog/2025-11-02-hermes-compilation-runtime-modes.md +23 -0
- package/hermes/doc/blog/2025-11-06-hermes-memory-modes.md +35 -0
- package/hermes/doc/blog/2025-11-24-json-parsing-performance.md +17 -0
- package/hermes/doc/blog/2025-12-02-iserialization.md +11 -0
- package/hermes/doc/blog/2025-12-12-new-way-to-contribute.md +68 -0
- package/hermes/doc/blog/2026-06-05-new-hermes-stable-release.md +51 -0
- package/hermes/doc/blog/README.md +25 -0
- package/hermes/doc/blog/images/2024-11-09-octane-pi3.jpeg +0 -0
- package/hermes/doc/blog/images/2024-11-09-octane-pi5.jpeg +0 -0
- package/hermes/doc/blog/images/2025-07-15-perf-hv32-interpreter.jpeg +0 -0
- package/hermes/doc/blog/images/2025-07-15-perf-hv32-jit.jpeg +0 -0
- package/hermes/doc/icu_license.txt +420 -0
- package/hermes/doc/img/heap_snapshot_retainers.png +0 -0
- package/hermes/doc/img/logo.svg +1 -0
- package/hermes/doc/img/object_captured_by_environment.png +0 -0
- package/hermes/doc/img/root_categories.png +0 -0
- package/hermes/doc/plans/ir-type/flow-type-system.md +324 -0
- package/hermes/doc/plans/ir-type/ir-type-system-v2-design.md +652 -0
- package/hermes/doc/plans/ir-type/ir-type-system.md +220 -0
- package/hermes/doc/plans/ir-type/ir-type-v2-implementation.md +1187 -0
- package/hermes/doc/plans/ir-type/memory.md +48 -0
- package/hermes/doc/plans/ir-type/phase1-steps.md +512 -0
- package/hermes/doc/plans/ir-type/progress.md +239 -0
- package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-design.md +203 -0
- package/hermes/doc/plans/ir-type/typeinference-primitive-fastpath-results.md +71 -0
- package/hermes/doc/superpowers/plans/2026-07-28-worker-arraybuffer-input.md +597 -0
- package/hermes/doc/superpowers/plans/2026-08-18-jitemitter-split.md +1149 -0
- package/hermes/doc/superpowers/plans/2026-08-20-jit-type-asserts.md +969 -0
- package/hermes/doc/superpowers/plans/2026-08-23-jit-shared-compiler-driver.md +478 -0
- package/hermes/doc/superpowers/plans/2026-08-23-x86-64-jit-skeleton.md +797 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-arith.md +444 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-calls.md +261 -0
- package/hermes/doc/superpowers/plans/2026-08-24-x86-64-jit-props.md +240 -0
- package/hermes/doc/superpowers/plans/2026-10-26-regexp-bytecode-sharing.md +2197 -0
- package/hermes/doc/superpowers/plans/2026-10-28-regexp-start-filter-and-exec-fast-paths.md +3981 -0
- package/hermes/doc/superpowers/specs/2026-07-28-worker-arraybuffer-input-design.md +206 -0
- package/hermes/doc/superpowers/specs/2026-08-18-jitemitter-split-design.md +530 -0
- package/hermes/doc/superpowers/specs/2026-08-20-jit-type-asserts-design.md +360 -0
- package/hermes/doc/superpowers/specs/2026-08-23-x86-64-jit-design.md +246 -0
- package/hermes/doc/superpowers/specs/2026-08-26-icu-free-normalize-design.md +355 -0
- package/hermes/doc/superpowers/specs/2026-08-27-icu-free-convert-to-case-design.md +305 -0
- package/hermes/doc/superpowers/specs/2026-08-27-icu-free-locale-compare-design.md +429 -0
- package/hermes/doc/superpowers/specs/2026-08-29-icu-free-date-format-design.md +297 -0
- package/hermes/doc/superpowers/specs/2026-10-26-regexp-bytecode-sharing-design.md +605 -0
- package/hermes/doc/superpowers/specs/2026-10-28-regexp-start-filter-and-exec-fast-paths-design.md +551 -0
- package/hermes/doc/typescript-stripping.md +90 -0
- package/hermes/external/CMakeLists.txt +20 -0
- package/hermes/utils/IntlGen/IntlGen.java +531 -0
- package/hermes/utils/bench_with_stats.py +827 -0
- package/hermes/utils/build-apple-framework.sh +323 -0
- package/hermes/utils/chrome_snapshot_parser.py +210 -0
- package/hermes/utils/cmake-dev-build.sh +18 -0
- package/hermes/utils/commons.sh +55 -0
- package/hermes/utils/dump-cpp-funcs.sh +3 -0
- package/hermes/utils/es5objects.js +198 -0
- package/hermes/utils/format.sh +145 -0
- package/hermes/utils/gen-promise-internal-bc.sh +66 -0
- package/hermes/utils/genUnicodeTable.py +2503 -0
- package/hermes/utils/hermes-lit/CMakeLists.txt +22 -0
- package/hermes/utils/hermes-lit/hermes-lit.in +15 -0
- package/hermes/utils/jit/README.md +134 -0
- package/hermes/utils/jit/jit-diff.sh +160 -0
- package/hermes/utils/jit/jit-dump.sh +193 -0
- package/hermes/utils/lit-expect-gen/generate.py +217 -0
- package/hermes/utils/promise/index.js +15 -0
- package/hermes/utils/promise/package.json +13 -0
- package/hermes/utils/promise/rollup.config.js +19 -0
- package/hermes/utils/promise/yarn.lock +247 -0
- package/hermes/utils/scripts/hermes/consts.js +26 -0
- package/hermes/utils/scripts/hermes/create-tarball.js +75 -0
- package/hermes/utils/scripts/hermes/get-hermes-version.js +57 -0
- package/hermes/utils/scripts/hermes/hermes-utils.js +122 -0
- package/hermes/utils/scripts/hermes/package.json +6 -0
- package/hermes/utils/scripts/hermes/prepare-artifacts.js +113 -0
- package/hermes/utils/scripts/hermes/publish-artifacts.js +109 -0
- package/hermes/utils/scripts/hermes/publish-npm.js +96 -0
- package/hermes/utils/scripts/hermes/scm-utils.js +41 -0
- package/hermes/utils/scripts/hermes/set-artifacts-version.js +64 -0
- package/hermes/utils/scripts/hermes/version-utils.js +98 -0
- package/hermes/utils/scripts/hermes/yarn.lock +240 -0
- package/hermes/utils/summarize_sizes.py +184 -0
- package/hermes/utils/symbolicate-nativecall-stats.py +112 -0
- package/hermes/utils/test_runner.py +13 -0
- package/hermes/utils/testsuite/README.facebook +3 -0
- package/hermes/utils/testsuite/README.md +69 -0
- package/hermes/utils/testsuite/cli.py +547 -0
- package/hermes/utils/testsuite/es_ast.py +337 -0
- package/hermes/utils/testsuite/external/LICENSE +28 -0
- package/hermes/utils/testsuite/external/README.facebook +8 -0
- package/hermes/utils/testsuite/external/__init__.py +0 -0
- package/hermes/utils/testsuite/external/_monkeyYaml.py +164 -0
- package/hermes/utils/testsuite/external/parse_test262.py +141 -0
- package/hermes/utils/testsuite/hermes.py +522 -0
- package/hermes/utils/testsuite/preprocess.py +365 -0
- package/hermes/utils/testsuite/progress.py +377 -0
- package/hermes/utils/testsuite/skiplist.json +4356 -0
- package/hermes/utils/testsuite/skiplist.py +270 -0
- package/hermes/utils/testsuite/test_run_defs.py +435 -0
- package/hermes/utils/testsuite/typing_defs.py +52 -0
- package/hermes/utils/testsuite/utils.py +214 -0
- package/hermes/utils/tidy.sh +22 -0
- package/hermes/utils/update-fbcode-hermes.sh +53 -0
- package/hermes/utils/updateErrorTest.py +193 -0
- package/hermes/utils/wasm-compile.sh +65 -0
- package/package.json +1 -1
package/hermes/doc/VM.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: vm
|
|
3
|
+
title: VM Overview
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Value Representation
|
|
7
|
+
|
|
8
|
+
### HermesValue
|
|
9
|
+
|
|
10
|
+
The VM uses a class called `HermesValue` to encapsulate JS values efficiently,
|
|
11
|
+
preserving their type while still allowing them to fit in a register.
|
|
12
|
+
NaN-tagging is used to store different types of values;
|
|
13
|
+
we store values in the lower bits of a `uint64_t`.
|
|
14
|
+
Thus, when the `uint64_t` is interpreted as a `double`,
|
|
15
|
+
tagged `NaN` values can hold non-`double` types.
|
|
16
|
+
|
|
17
|
+
After we reserve the canonical quiet NaN to be used as the NaN representation
|
|
18
|
+
in the VM, we have 51 remaining bits we can set. Even on 64-bit systems, we are
|
|
19
|
+
able to accommodate a full pointer and type tag, since pointers are never more
|
|
20
|
+
than 48 bits in practice.
|
|
21
|
+
|
|
22
|
+
A `HermesValue` can take on any of the following types of values, which are
|
|
23
|
+
distinguished by their type tag:
|
|
24
|
+
1. Empty
|
|
25
|
+
2. Undefined
|
|
26
|
+
3. Null
|
|
27
|
+
4. Boolean
|
|
28
|
+
5. Symbol
|
|
29
|
+
6. Native value (used to store an int or pointer for bookkeeping)
|
|
30
|
+
7. String pointer
|
|
31
|
+
8. Object pointer
|
|
32
|
+
|
|
33
|
+
`HermesValue` is used across the VM to store and pass JS values.
|
|
34
|
+
`PinnedHermesValue` is used in non-moveable memory, primarily for the register
|
|
35
|
+
stack and other GC roots in known locations in memory. `GCHermesValue`s are
|
|
36
|
+
used on the GC managed heap.
|
|
37
|
+
|
|
38
|
+
### HermesValue32
|
|
39
|
+
|
|
40
|
+
When compressed pointers are enabled, we also encode some values in a compact
|
|
41
|
+
32-bit representation called `HermesValue32`. Because compressing pointers to
|
|
42
|
+
store in this format requires additional work, we also avoid using
|
|
43
|
+
`HermesValue32` for frequently accessed values (like the register stack).
|
|
44
|
+
Instead we selectively use `HermesValue32` for objects that are known to
|
|
45
|
+
consume a large percentage of heap memory, but that are unlikely to affect
|
|
46
|
+
performance.
|
|
47
|
+
|
|
48
|
+
`HermesValue32` supports storing all of the types that `HermesValue` does,
|
|
49
|
+
except for native values, which were dropped because they are relatively rare
|
|
50
|
+
and because we do not have a mechanism for compressing native pointers outside
|
|
51
|
+
the GC managed heap.
|
|
52
|
+
|
|
53
|
+
Instead of using NaN boxing, it takes advantage of the 8-byte alignment of the
|
|
54
|
+
Hermes heap to store tags, since the lowest 3 bits of a pointer are always
|
|
55
|
+
guaranteed to be zero (even after compression).
|
|
56
|
+
|
|
57
|
+
`HermesValue32` also requires special handling for doubles. It is able to store
|
|
58
|
+
small integers up to 29 bits inline, but anything that cannot be represented in
|
|
59
|
+
that form must be stored as a separate double object on the heap. Based on the
|
|
60
|
+
workloads we have looked at, actual doubles are very rarely used, so the
|
|
61
|
+
overhead of this approach is small.
|
|
62
|
+
|
|
63
|
+
### Strings
|
|
64
|
+
|
|
65
|
+
`StringPrimitive` is used to store immutable UTF16 encoded strings,
|
|
66
|
+
and `StringPrimitive *` can be stored in `HermesValue` to make JS String values.
|
|
67
|
+
|
|
68
|
+
Internally, `StringPrimitive` can be
|
|
69
|
+
- `DynamicStringPrimitive` (stored in the GC heap)
|
|
70
|
+
- `ExternalStringPrimitive` (stored as a pointer outside the VM, such as into a bytecode file)
|
|
71
|
+
|
|
72
|
+
## Runtime
|
|
73
|
+
|
|
74
|
+
The `Runtime` class is the primary driver of the VM.
|
|
75
|
+
It contains the current environment and heap, as well as the code to execute.
|
|
76
|
+
`Runtime` is used to execute `RuntimeModule`s,
|
|
77
|
+
which are constructed from `BytecodeModule`s using `Runtime::runModule()`.
|
|
78
|
+
|
|
79
|
+
### Runtime Module
|
|
80
|
+
|
|
81
|
+
A `RuntimeModule` is the VM representation into a bytecode file.
|
|
82
|
+
`RuntimeModule`s are stored outside the GC heap and are constructed via `new`.
|
|
83
|
+
|
|
84
|
+
To allow for segmentation of bytecode files and `require`ing modules between
|
|
85
|
+
separate segments, we collect `RuntimeModule`s in a class called `Domain`.
|
|
86
|
+
You may think of the `Domain` as the collection of bytecode files which were
|
|
87
|
+
all compiled in the same invocation of the compiler.
|
|
88
|
+
|
|
89
|
+
Every `JSFunction` shares ownership of a `Domain`, and the `Domain` owns
|
|
90
|
+
the `RuntimeModule`s which provide those functions. In this way, when all
|
|
91
|
+
`JSFunction`s which require the files in a `Domain` are collected,
|
|
92
|
+
the `Domain` and the `RuntimeModule`s are also collected.
|
|
93
|
+
|
|
94
|
+
### Runtime Identifiers
|
|
95
|
+
|
|
96
|
+
The `Runtime` contains an `IdentifierTable`,
|
|
97
|
+
which is used for getting unique IDs for strings.
|
|
98
|
+
The table is used to go from `StringPrimitive` to `SymbolID` and back.
|
|
99
|
+
It's prepopulated with some "predefined strings",
|
|
100
|
+
the set of strings that are required by built in functions,
|
|
101
|
+
which can be seen in `PredefinedStrings.def`.
|
|
102
|
+
|
|
103
|
+
### Garbage Collection
|
|
104
|
+
|
|
105
|
+
Currently, the VM uses `HadesGC` by default, a concurrent garbage collector aimed at dramatically lowering pause times over our previous collector [GenGC](./GenGC.md). The heap in Hermes is non-contiguous, which allows us to avoid reserving large regions of address space upfront, and allows us to return memory to the OS at a finer granularity. Garbage collection in Hermes is precise, which means that the GC always knows which values contain valid pointers.
|
|
106
|
+
|
|
107
|
+
See the documentation for [Hades](./Hades.md) for details
|
|
108
|
+
on how it works.
|
|
109
|
+
|
|
110
|
+
The garbage collector moves objects to different place on the heap,
|
|
111
|
+
invalidating `HermesValue`s,
|
|
112
|
+
so there are a couple classes which allow updating them automatically.
|
|
113
|
+
`Handle<>` and `Handle<T>` are garbage collector-aware handles;
|
|
114
|
+
they are moved if a collection occurs in between two successive accesses.
|
|
115
|
+
So, to ensure correctness in the VM,
|
|
116
|
+
use the handles instead of passing raw `HermesValue` between functions.
|
|
117
|
+
|
|
118
|
+
A `GCScope` is used to keep track of all the current `HermesValue` handles.
|
|
119
|
+
Any `GCScope` must be constructed on the stack,
|
|
120
|
+
whence it tracks any scoped handles that are used until it falls out of scope.
|
|
121
|
+
The `GCScope` allocates space in chunks,
|
|
122
|
+
and when it is destroyed (falls out of scope) it frees any chunks it allocated.
|
|
123
|
+
The `GCScope` is used to internally generate `PinnedHermesValue`s,
|
|
124
|
+
which are then stored in `Handle<>` and `Handle<T>`.
|
|
125
|
+
|
|
126
|
+
We also provide `PseudoHandle<T>` classes which are explicitly *not* handles.
|
|
127
|
+
These are used to be explicit about storage of raw pointers and `HermesValue`.
|
|
128
|
+
`PseudoHandle` should be used as an argument in place of a raw pointer to
|
|
129
|
+
functions which may want to turn that argument into a `Handle`,
|
|
130
|
+
but in which it's not necessary to *always* incur the cost of handle allocation.
|
|
131
|
+
`PseudoHandle` also does not have a copy constructor,
|
|
132
|
+
and moving out of one invalidates it.
|
|
133
|
+
This prevents the reuse of `PseudoHandle` after an allocating function call.
|
|
134
|
+
|
|
135
|
+
#### Rules for GC-safe code
|
|
136
|
+
|
|
137
|
+
See [GCSafeCoding.md](GCSafeCoding.md) for the complete guide to writing correct
|
|
138
|
+
and performant GC-safe C++ code, including the preferred `Locals` + `PinnedValue`
|
|
139
|
+
API, handle usage, error handling patterns, and common mistakes.
|
|
140
|
+
|
|
141
|
+
## Object Model
|
|
142
|
+
|
|
143
|
+
Currently the object model is a VTable-based scheme,
|
|
144
|
+
in which all possible JS values inherit from a base garbage collector VTable.
|
|
145
|
+
These are called "cells", and all the cells are defined in `CellKinds.def`.
|
|
146
|
+
Objects have a special `ObjectVTable`, Callables have a `CallableVTable`, etc.
|
|
147
|
+
|
|
148
|
+
### Objects
|
|
149
|
+
|
|
150
|
+
Each JS object is represented by `Object` (or a class derived from `Object`).
|
|
151
|
+
JS objects have a set of name/value pairs, and some optional "indexed storage".
|
|
152
|
+
Read more about how `Object` works in `ObjectModel.h`.
|
|
153
|
+
The Runtime contains a global object which is used to store in global scope.
|
|
154
|
+
|
|
155
|
+
### Arrays
|
|
156
|
+
|
|
157
|
+
Arrays, the `arguments` object, etc. inherit from Object directly,
|
|
158
|
+
but simply provide their own implementations of `*OwnIndexed` using the VTable.
|
|
159
|
+
|
|
160
|
+
### Functions
|
|
161
|
+
|
|
162
|
+
Functions and native functions inherit from `Callable`.
|
|
163
|
+
This allows them to call `executeCall*` to run functions using the internal API.
|
|
164
|
+
|
|
165
|
+
### Boxed Primitives
|
|
166
|
+
|
|
167
|
+
The VM has classes used to contain Booleans, Strings, and Numbers,
|
|
168
|
+
when they are constructed using their respective JS constructors.
|
|
169
|
+
`JSString` is a boxed `String` object, etc.
|
|
170
|
+
|
|
171
|
+
## REPL
|
|
172
|
+
|
|
173
|
+
The HermesVM provides a REPL in `bin/hermes`,
|
|
174
|
+
which calls through to the `eval()` global function in the `Runtime`.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Octane Benchmark Results: Hermes JIT Progress
|
|
2
|
+
|
|
3
|
+
*November 9, 2024 · tmikov*
|
|
4
|
+
|
|
5
|
+
In parallel with typed JS, we have also been making progress on untyped (legacy) JS performance.
|
|
6
|
+
|
|
7
|
+
These are Octane benchmark results comparing original Hermes, the static_h branch, and static_h branch with JIT. I also added QuickJS for reference. The TypeScript benchmark was removed because it is too high.
|
|
8
|
+
|
|
9
|
+
The benchmarks were run on Raspberry Pi 3 and Pi 5 to encompass a wide range of performance.
|
|
10
|
+
|
|
11
|
+
This is all untyped, unannotated JS, not using the native backend.
|
|
12
|
+
|
|
13
|
+
To be clear, Octane is not representative these days, but we can't have good performance in more important cases if we completely suck at Octane. Higher scores are better.
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+

|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Static Hermes Update, December 2024
|
|
2
|
+
|
|
3
|
+
*December 19, 2024 · tmikov*
|
|
4
|
+
|
|
5
|
+
Throughout much of 2024, the Hermes team has been focused on improving both the performance and ECMAScript compliance of untyped JavaScript. While the primary goal of the Static Hermes project is to achieve native-like performance with typed JavaScript, we recognize that a significant amount of untyped code must also execute correctly and efficiently.
|
|
6
|
+
|
|
7
|
+
This post highlights some of the key improvements we've made in the static_h branch of Hermes. The static_h branch supports both typed and untyped compilation and execution. We are working toward making the static_h branch opt-in initially, and later the default React Native engine next year.
|
|
8
|
+
|
|
9
|
+
## Major Advances in ECMAScript Compliance
|
|
10
|
+
|
|
11
|
+
**Full spec-compliant implementation of ES6 classes.** This does not include private fields and static blocks, but support is already under way.
|
|
12
|
+
|
|
13
|
+
Our classes implementation is ~2.3x faster at constructing instances of a class, and ~4.5x faster in super invocations compared to Babel's strict transform. Additionally, we are ~1.35x and ~1.15x, respectively, faster than Babel's loose transform, all while remaining fully spec-compliant.
|
|
14
|
+
|
|
15
|
+
**Full block scoping support for `let`, `const` and Temporal Dead Zone (TDZ)**, with an option to disable TDZ for increased performance.
|
|
16
|
+
|
|
17
|
+
These features have been a long time coming and represent a significant step forward in closing the gap in Hermes' functionality—though this gap has largely been mitigated by React Native's Babel pipeline. Now, we are finally here.
|
|
18
|
+
|
|
19
|
+
## Untyped JS Performance Wins
|
|
20
|
+
|
|
21
|
+
The table below shows the "times x" performance improvements in Octane benchmarks of the static_h branch compared to the main Hermes branch. The first column represents performance with the regular interpreter, while the second column shows results with JIT enabled.
|
|
22
|
+
|
|
23
|
+
The last three benchmarks are custom additions by our team. These benchmarks highlight, among other things, the dramatic performance improvements of the JIT when more type information is available.
|
|
24
|
+
|
|
25
|
+
In the InterpDispatch2 and Mandelbrot benchmarks, our compiler was able to statically infer many types, resulting in significant speed-ups. With typed JavaScript, these numbers are expected to climb even higher.
|
|
26
|
+
|
|
27
|
+
| Benchmark | Normal | JIT |
|
|
28
|
+
|------------------|--------|------|
|
|
29
|
+
| Richards | 1.24 | 1.78 |
|
|
30
|
+
| DeltaBlue | 1.29 | 1.86 |
|
|
31
|
+
| Crypto | 1.34 | 1.91 |
|
|
32
|
+
| RayTrace | 1.72 | 2.07 |
|
|
33
|
+
| EarleyBoyer | 1.49 | 1.71 |
|
|
34
|
+
| RegExp | 1.20 | 1.20 |
|
|
35
|
+
| Splay | 1.22 | 1.33 |
|
|
36
|
+
| SplayLatency | 1.09 | 1.15 |
|
|
37
|
+
| NavierStokes | 1.50 | 1.87 |
|
|
38
|
+
| PdfJS | 1.68 | 1.78 |
|
|
39
|
+
| Mandreel | 1.38 | 1.69 |
|
|
40
|
+
| MandreelLatency | 1.36 | 1.42 |
|
|
41
|
+
| Gameboy | 1.36 | 1.68 |
|
|
42
|
+
| Box2D | 1.41 | 1.93 |
|
|
43
|
+
| zlib | 1.65 | 2.04 |
|
|
44
|
+
| Typescript | 1.28 | 1.46 |
|
|
45
|
+
| InterpDispatch | 1.66 | 2.97 |
|
|
46
|
+
| InterpDispatch2 | 1.58 | 7.90 |
|
|
47
|
+
| Mandelbrot | 1.25 | 3.29 |
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# Compiling Full-Featured JavaScript to Wasm
|
|
2
|
+
|
|
3
|
+
*December 23, 2024 · tmikov*
|
|
4
|
+
|
|
5
|
+
Compiling JavaScript to Wasm ahead of time has always been a fascinating topic. However, to my knowledge, there is no close-to-production-quality solution currently capable of statically compiling the full ES6 JavaScript language to Wasm without relying on an interpreter.
|
|
6
|
+
|
|
7
|
+
I would like to demonstrate how easily Static Hermes enables us to do precisely that.
|
|
8
|
+
|
|
9
|
+
This article has been a long time coming, since I have posted more than once that Static Hermes can produce Wasm, but I never actually had the time to sit down, write the instructions, and fix a couple of minor problems that appeared.
|
|
10
|
+
|
|
11
|
+
> **NOTE:** [Porffor](https://porffor.dev/) definitely deserves a mention here: it is an exciting emerging project exploring this space while taking a different approach. While it is not production quality yet, it shows real promise.
|
|
12
|
+
|
|
13
|
+
## But Why Do It at All?
|
|
14
|
+
|
|
15
|
+
Compiling JS to Wasm, while perhaps not a game-changer for everyday JavaScript execution, opens up a world of intriguing possibilities. For example:
|
|
16
|
+
|
|
17
|
+
- It provides sandbox isolation.
|
|
18
|
+
- It allows Wasm hosts that lack a JS engine to still run JavaScript.
|
|
19
|
+
- It allows standalone applications to embed the runtime, built-ins, and compiled code into a single Wasm binary.
|
|
20
|
+
|
|
21
|
+
## What is Static Hermes (and Hermes)
|
|
22
|
+
|
|
23
|
+
Hermes is an optimized JavaScript engine designed to execute JavaScript efficiently on resource-constrained devices, particularly phones. It is the default JS engine of React Native, a cross-platform mobile development framework. Hermes has been deployed to hundreds of millions of devices, including desktop computers and servers.
|
|
24
|
+
|
|
25
|
+
Static Hermes (which lives in the [static_h branch](https://github.com/facebook/hermes/tree/static_h)) is the code name for the next generation of Hermes, which, among other things, focuses on optional sound typing and optional ahead-of-time (AOT) compilation of JavaScript to native code.
|
|
26
|
+
|
|
27
|
+
The native compilation aspect of Static Hermes is what makes it particularly suitable to the task at hand - compiling JavaScript to Wasm.
|
|
28
|
+
|
|
29
|
+
Static Hermes already supports compiling the full JavaScript language to native code. By leveraging Clang and LLVM for code generation, it can treat WebAssembly (Wasm) as just another compiler target. This approach allows Static Hermes to compile the complete ES6 JavaScript language into Wasm while preserving the language's flexibility and dynamic nature.
|
|
30
|
+
|
|
31
|
+
The resulting Wasm binaries are highly comprehensive and contain:
|
|
32
|
+
|
|
33
|
+
- **Compiled JavaScript:** The input JavaScript translated directly into Wasm instructions for efficient execution, without the JS interpreter. We will look at a detailed example later in this article.
|
|
34
|
+
- **JavaScript Library:** All standard built-ins, such as Object, Array, and Math, are included to ensure compatibility.
|
|
35
|
+
- **Embedded Interpreter:** Dynamic features like `eval()` and `new Function()` are supported through an integrated interpreter, activated only when required.
|
|
36
|
+
|
|
37
|
+
In the next section, we will see how to build Static Hermes and use it to compile JavaScript to Wasm and how to run the resulting Wasm binaries.
|
|
38
|
+
|
|
39
|
+
## Getting Started with Static Hermes and Wasm
|
|
40
|
+
|
|
41
|
+
For those interested in exploring Static Hermes for compiling JavaScript to WebAssembly, the process is straightforward and involves a few key steps. Rather than detailing them all here, I have created a guide to walk through:
|
|
42
|
+
|
|
43
|
+
1. Setting up the development environment with Emscripten and the static_h branch of Hermes.
|
|
44
|
+
2. Building the Hermes JSVM for your host platform and for Wasm.
|
|
45
|
+
3. Running simple JavaScript applications and benchmarks using the Hermes VM Wasm binary. This involves running the Hermes VM in Wasm mode, which functions as an interpreter.
|
|
46
|
+
|
|
47
|
+
The final step, compiling JavaScript applications to independent Wasm binaries, highlights Static Hermes's unique capabilities. This process produces a fully self-contained Wasm binary.
|
|
48
|
+
|
|
49
|
+
The guide includes the necessary commands, configurations, and options to begin experimenting with Static Hermes and Wasm. It can be found here: [doc/Emscripten.md](https://github.com/facebook/hermes/blob/static_h/doc/Emscripten.md).
|
|
50
|
+
|
|
51
|
+
If you find inaccuracies in the guide, or have ideas how to improve it, PRs and comments are welcome.
|
|
52
|
+
|
|
53
|
+
Please, keep in mind that while the Static Hermes interpreter has already been shipped in production, the native compilation functionality is still considered experimental (but is not expected to have major bugs).
|
|
54
|
+
|
|
55
|
+
## Exploring the Generated Wasm Code
|
|
56
|
+
|
|
57
|
+
To understand the results of Static Hermes's compilation, let's take a closer look at a simple example. The following JavaScript function computes the sum of integers from 0 to a given number `to`:
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
function sum(to) {
|
|
61
|
+
to = +to;
|
|
62
|
+
let sum = 0;
|
|
63
|
+
for(let i = 0; i < to; ++i)
|
|
64
|
+
sum += i;
|
|
65
|
+
return sum;
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The statement `to = +to` is interesting. It ensures that `to` is explicitly converted to a number, enabling us to infer types throughout the function. Type inference allows Static Hermes to optimize the generated Wasm code by treating `to`, `i`, and `sum` as numbers consistently, avoiding the overhead of type checks and conversions during execution.
|
|
70
|
+
|
|
71
|
+
> **NOTE:** The example would work without that, but would be slower and much more verbose.
|
|
72
|
+
|
|
73
|
+
After compilation with Static Hermes, this function is transformed into WebAssembly (Wasm) code. The assembly listing is too long to reproduce here, but we can examine the most important part - the loop.
|
|
74
|
+
|
|
75
|
+
```wasm
|
|
76
|
+
loop ;; label = @2
|
|
77
|
+
local.get 5 ;; Get the current sum
|
|
78
|
+
local.get 6 ;; Get the current value of `i`
|
|
79
|
+
f64.add ;; Add `i` to the sum
|
|
80
|
+
local.set 6 ;; Store the result back into `sum`
|
|
81
|
+
local.get 5 ;; Increment `i`
|
|
82
|
+
f64.const 0x1p+0 ;; Load the constant 1 (as a floating point)
|
|
83
|
+
f64.add ;; Add 1 to `i`
|
|
84
|
+
local.tee 5 ;; Store the incremented value into `i` and leave it on the stack
|
|
85
|
+
local.get 4 ;; Get the upper bound `to`
|
|
86
|
+
f64.lt ;; Compare `i` with `to`
|
|
87
|
+
br_if 0 (;@2;) ;; If `i >= to`, break
|
|
88
|
+
end
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
This Wasm loop corresponds directly to the JavaScript `for` loop. Key operations such as updating the sum, incrementing the loop counter, and checking the loop condition are reflected in the Wasm instructions:
|
|
92
|
+
|
|
93
|
+
- `local.get` and `local.set` manage local variables like `sum` and `i`.
|
|
94
|
+
- `f64.add` handles floating-point addition, used here to increment `i` and update `sum`.
|
|
95
|
+
- `f64.lt` compares `i` to the loop limit `to`.
|
|
96
|
+
- `br_if` provides the conditional branching mechanism to terminate the loop.
|
|
97
|
+
|
|
98
|
+
### Observations
|
|
99
|
+
|
|
100
|
+
- **Explicitness:** The Wasm representation is verbose, reflecting its low-level nature. Each operation (e.g., addition, comparison) is explicitly represented, enabling precise control over execution.
|
|
101
|
+
- **Efficiency:** The use of floating-point instructions (`f64.*`) reflects the type inference the compiler is able to perform, turning dynamic typing into static.
|
|
102
|
+
- **Direct Mapping:** The loop in the JavaScript code maps fairly cleanly to the Wasm code. This is not always the case with more complex code and optimizations, but is fun to see.
|
|
103
|
+
|
|
104
|
+
## Advanced JavaScript
|
|
105
|
+
|
|
106
|
+
I have prepared a small script, `demo.js`, demonstrating some more advanced JavaScript features, including closures, TDZ behavior, and prototype manipulation, which are faithfully supported by Static Hermes when compiled to Wasm.
|
|
107
|
+
|
|
108
|
+
### Compile and Run demo.js
|
|
109
|
+
|
|
110
|
+
Assuming you have just successfully completed the "Getting Started" instructions, make sure `demo.js` is in the current directory and compile it.
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
${HermesSourcePath?}/utils/wasm-compile.sh build-host build-wasm demo.js
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The command should output something like:
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
Using shermes to compile demo.js... to demo.c
|
|
120
|
+
Using emcc to compile demo.c to demo.o
|
|
121
|
+
Using emcc to link demo.o to demo-wasm.js/.wasm
|
|
122
|
+
-rw-r--r-- 1 user group 73K Dec 23 17:35 demo-wasm.js
|
|
123
|
+
-rwxr-xr-x 1 user group 2.6M Dec 23 17:35 demo-wasm.wasm
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Now we can run the result and enjoy the awesome power of Wasm!
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
node ./demo-wasm.js
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
Closures
|
|
134
|
+
=========
|
|
135
|
+
Generating 5 increments with default step size:
|
|
136
|
+
1
|
|
137
|
+
... and so on
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
The following sections provide a brief tour of `demo.js`, showcasing that Static Hermes handles various JavaScript features.
|
|
141
|
+
|
|
142
|
+
### Closures and Generators
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
function createCounterWithGenerator() {
|
|
146
|
+
let count = 0; // Shared mutable variable
|
|
147
|
+
|
|
148
|
+
// Default parameter.
|
|
149
|
+
const increment = (by = 1) => count += by;
|
|
150
|
+
|
|
151
|
+
// Generator captures a peer closure (increment).
|
|
152
|
+
function* doSteps(steps) {
|
|
153
|
+
for (let i = 0; i < steps; i++)
|
|
154
|
+
yield increment();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Shorthand object literal.
|
|
158
|
+
return {
|
|
159
|
+
increment,
|
|
160
|
+
doSteps
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const counter = createCounterWithGenerator();
|
|
165
|
+
|
|
166
|
+
// Tagged template literal
|
|
167
|
+
console.log(`Generating ${steps} increments with default step size:`);
|
|
168
|
+
// For-of with a generator
|
|
169
|
+
for (const value of counter.doSteps(steps))
|
|
170
|
+
console.log(value);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Temporal Dead Zone (TDZ)
|
|
174
|
+
|
|
175
|
+
The `show_tdz()` function illustrates TDZ errors arising from improper use of `let`.
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
function show_tdz() {
|
|
179
|
+
function getval() {
|
|
180
|
+
return val;
|
|
181
|
+
}
|
|
182
|
+
// Reading val before it is initialized.
|
|
183
|
+
let val = getval() + 1;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
console.log("\nTDZ\n=========");
|
|
187
|
+
try {
|
|
188
|
+
show_tdz();
|
|
189
|
+
} catch (e) {
|
|
190
|
+
console.log("TDZ Error!", e.stack);
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Prototypical Inheritance
|
|
195
|
+
|
|
196
|
+
The example uses prototype chains and dynamic getters, showcasing inheritance and dynamic property manipulation.
|
|
197
|
+
|
|
198
|
+
```javascript
|
|
199
|
+
const prototypeObj = {
|
|
200
|
+
first: "I am in the prototype"
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const obj = {
|
|
204
|
+
get second() {
|
|
205
|
+
// Add and increment the `third` property
|
|
206
|
+
if (!this.third) {
|
|
207
|
+
this.third = 1; // Initialize if it doesn't exist
|
|
208
|
+
} else {
|
|
209
|
+
this.third++;
|
|
210
|
+
}
|
|
211
|
+
return `Getter executed, third is now ${this.third}`;
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
__proto__: prototypeObj // Set prototype using object literal syntax
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
console.log("First property:", obj.first); // Inherited from prototype
|
|
218
|
+
console.log("Second property:", obj.second); // Triggers the getter
|
|
219
|
+
console.log("Third property:", obj.third); // Dynamically added and incremented
|
|
220
|
+
console.log("Second property again:", obj.second); // Getter increments third
|
|
221
|
+
console.log("Third property now:", obj.third); // Reflects incremented value
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### ES6 Classes
|
|
225
|
+
|
|
226
|
+
Demonstrates inheritance and property handling with ES6 classes.
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
class PrototypeClass {
|
|
230
|
+
constructor() {}
|
|
231
|
+
|
|
232
|
+
// Define `first` as a getter in the prototype
|
|
233
|
+
get first() {
|
|
234
|
+
return "I am in the prototype";
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
class DerivedClass extends PrototypeClass {
|
|
239
|
+
constructor() {
|
|
240
|
+
super();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
get second() {
|
|
244
|
+
// Add and increment the `third` property
|
|
245
|
+
if (!this.third) {
|
|
246
|
+
this.third = 1; // Initialize if it doesn't exist
|
|
247
|
+
} else {
|
|
248
|
+
this.third++;
|
|
249
|
+
}
|
|
250
|
+
return `Getter executed, third is now ${this.third}`;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const clInst = new DerivedClass();
|
|
255
|
+
|
|
256
|
+
console.log("First property:", clInst.first); // Inherited from PrototypeClass
|
|
257
|
+
console.log("Second property:", clInst.second); // Triggers the getter
|
|
258
|
+
console.log("Third property:", clInst.third); // Dynamically added and incremented
|
|
259
|
+
console.log("Second property again:", clInst.second); // Getter increments third
|
|
260
|
+
console.log("Third property now:", clInst.third); // Reflects incremented value
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Conclusion
|
|
264
|
+
|
|
265
|
+
Static Hermes is an ambitious project that pushes the boundaries of what JavaScript can do. The ability to compile the full ES6 standard to Wasm, while preserving JavaScript's flexibility, opens up some fascinating possibilities.
|
|
266
|
+
|
|
267
|
+
If this kind of thing interests you, check out the [Static Hermes source code](https://github.com/facebook/hermes/tree/static_h). Try it out, poke around, and feel free to ask questions. Contributions and discussions are always welcome.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Introducing JSI's New Runtime Data APIs
|
|
2
|
+
|
|
3
|
+
*June 9, 2025 · tmikov*
|
|
4
|
+
|
|
5
|
+
We noticed a common pattern emerging in React Native (RN) libraries - a map from `jsi::Runtime *` to some per-runtime data. This approach has proven clumsy and problematic, because of unclear map ownership and lifetime. To address this, we recently introduced two new methods to `jsi::Runtime`: `setRuntimeData()` and `getRuntimeData()`.
|
|
6
|
+
|
|
7
|
+
```cpp
|
|
8
|
+
/// Stores the pointer \p data with the \p uuid in the runtime. This can be
|
|
9
|
+
/// used to store some custom data within the runtime. When the runtime is
|
|
10
|
+
/// destroyed, or if an entry at an existing key is overwritten, the runtime
|
|
11
|
+
/// will release its ownership of the held object.
|
|
12
|
+
void setRuntimeData(const UUID& uuid, const std::shared_ptr<void>& data);
|
|
13
|
+
|
|
14
|
+
/// Returns the data associated with the \p uuid in the runtime. If there's no
|
|
15
|
+
/// data associated with the uuid, return a null pointer.
|
|
16
|
+
std::shared_ptr<void> getRuntimeData(const UUID& uuid);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The `setRuntimeData()` method allows storage of a `std::shared_ptr<void>` associated with a UUID, with the runtime managing ownership and releasing it upon destruction or overwrite. The `getRuntimeData()` method retrieves this data for a given UUID, returning a null pointer if none exists. This approach eliminates the need for custom maps and eliminates any uncertainty about ownership and lifetime.
|
|
20
|
+
|
|
21
|
+
An immediate practical application would be storing cached instances of `jsi::PropNameID`, which are runtime-specific uniqued strings.
|
|
22
|
+
|
|
23
|
+
**Why UUIDs?** UUIDs are 128-bit values designed to be globally unique, even without central coordination. They are necessary here to avoid conflicts between independent libraries using the same runtime. You could use one for all your per-runtime data, or multiple for different things - it is up to you.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Static_h Branch Performance: June 2025 Update
|
|
2
|
+
|
|
3
|
+
*July 15, 2025 · tmikov*
|
|
4
|
+
|
|
5
|
+
static_h branch performance at end of June 2025, relative to Hermes and QuickJS. Numbers are relative to QuickJS (1.2 means 1.2x faster); higher is better.
|
|
6
|
+
|
|
7
|
+
The measured Hermes v2 configuration is hv32+jit.
|
|
8
|
+
|
|
9
|
+
- **hv32** means the runtime uses compressed pointers and boxed doubles, when they don't fit in a 32-bit tagged value.
|
|
10
|
+
- **jit** means JIT 😅
|
|
11
|
+
|
|
12
|
+
QuickJS is used as a performance reference, since it is high quality, small, and spec compliant.
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
static_h branch hv32+interpreter performance, relative to QuickJS and Hermes (higher is better).
|
|
17
|
+
|
|
18
|
+

|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Hermes Compilation and Runtime Modes
|
|
2
|
+
|
|
3
|
+
*November 2, 2025 · tmikov*
|
|
4
|
+
|
|
5
|
+
Hermes has the following compilation "modes":
|
|
6
|
+
|
|
7
|
+
- AOT compilation of typed or untyped JS to bytecode
|
|
8
|
+
- AOT compilation of typed or untyped JS to native code
|
|
9
|
+
|
|
10
|
+
Plus the following runtime modes:
|
|
11
|
+
|
|
12
|
+
- Native execution
|
|
13
|
+
- Bytecode interpreter
|
|
14
|
+
- Lazy compilation (source to bytecode) of each function the first time it is called
|
|
15
|
+
- Baseline JIT (bytecode to native) of frequently executed functions
|
|
16
|
+
|
|
17
|
+
All of these modes can be mixed and exist in the same runtime simultaneously. An app could use all of these:
|
|
18
|
+
|
|
19
|
+
1. Some code compiled to native
|
|
20
|
+
2. Some code compiled to bytecode (to save space)
|
|
21
|
+
3. Some source (perhaps generated at runtime)
|
|
22
|
+
|
|
23
|
+
If the JIT is enabled, parts of (2) and (3) will be JIT-ed to native if they become hot enough.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Hermes Memory Modes
|
|
2
|
+
|
|
3
|
+
*November 6, 2025 · tmikov*
|
|
4
|
+
|
|
5
|
+
Hermes has the following memory modes:
|
|
6
|
+
|
|
7
|
+
## HV64 (all platforms)
|
|
8
|
+
|
|
9
|
+
This is usually the simplest mode - all JS values, pointers, and numbers are encoded as 64-bit values using NaN-boxing.
|
|
10
|
+
|
|
11
|
+
## HV32 on 32-bit devices
|
|
12
|
+
|
|
13
|
+
JS values and pointers are encoded as 32-bit values. Some numbers are encoded as 32-bit values. The ones that do not fit in 32-bit are boxed in the heap. Fortunately, in most apps this is a really small percentage.
|
|
14
|
+
|
|
15
|
+
This mode has a small overhead, but it saves a lot of memory, obviously, and can be a performance win because of smaller cache footprint.
|
|
16
|
+
|
|
17
|
+
## HV32 for 64-bit platforms (except iOS)
|
|
18
|
+
|
|
19
|
+
JS values and pointers are encoded as 32-bit values. All memory is allocated in a (up to) 4GB reserved contiguous memory block and all pointers are 32-bit offsets inside it.
|
|
20
|
+
|
|
21
|
+
This mode similarly has some overhead but saves a lot of memory, and can be a performance win because of smaller cache footprint.
|
|
22
|
+
|
|
23
|
+
## HV32 for iOS (64-bit)
|
|
24
|
+
|
|
25
|
+
iOS is special, since it doesn't by default allow an app to allocate a lot of virtual address space (without a special entitlement). So, Hermes allocates memory in 4MB segments. Each segment can be anywhere in the 64-bit address space, so there is no way to directly encode a 64-bit address in a 32-bit pointer.
|
|
26
|
+
|
|
27
|
+
So, Hermes maintains a table with one entry per segment. 32-bit pointers are a combination of index in the table and offset in the segment (I am simplifying a bit, but the principle remains).
|
|
28
|
+
|
|
29
|
+
This mode also saves a lot of memory like the other HV32 ones, but has more overhead. iOS devices usually are faster, so it is not as visible.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
As you can see, Hermes is very configurable. A lot of work has gone into supporting different kinds of systems.
|
|
34
|
+
|
|
35
|
+
With Hermes V1, by default we are going to ship HV32 on Android devices and HV64 on iOS devices in order to get best performance from the latter.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# JSON Parsing Performance: 2.7x-3.4x Faster
|
|
2
|
+
|
|
3
|
+
*November 24, 2025 · tmikov*
|
|
4
|
+
|
|
5
|
+
Big news for Hermes JSON parsing. Michael from our team worked on speeding it up for the last month - the result is between 2.7x-3.4x faster! It is available in the static_h branch now and will be included in the next stable releases.
|
|
6
|
+
|
|
7
|
+
Incomplete list of improvements:
|
|
8
|
+
|
|
9
|
+
- Switch to an iterative parser
|
|
10
|
+
- Cache object hidden classes
|
|
11
|
+
- Optimize string parsing
|
|
12
|
+
- Use [@lemire](https://x.com/lemire)'s [fast_float](https://github.com/fastfloat/fast_float)
|
|
13
|
+
- Add an even faster number path for integers
|
|
14
|
+
- Avoid unnecessary allocations
|
|
15
|
+
- Use a per-character lookup and function dispatch table
|
|
16
|
+
|
|
17
|
+
Coming up next: JSON.stringify().
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# ISerialization: Efficient Binary Encoding for JS Values
|
|
2
|
+
|
|
3
|
+
*December 2, 2025 · tmikov*
|
|
4
|
+
|
|
5
|
+
ISerialization just landed in the static_h branch and will be out in the next stable release.
|
|
6
|
+
|
|
7
|
+
ISerialization encodes a JS value into an efficient opaque binary representation, which can then be de-serialized (deeply cloned) in one or more runtime instances.
|
|
8
|
+
|
|
9
|
+
It also optionally supports serialization with ownership transfer.
|
|
10
|
+
|
|
11
|
+
It is intended for efficient passing of values between runtimes and will be the base of message passing in our implementation of Web Workers.
|