Commit 3a8c8a9
Remove embind from Yoga JavaScript bindings (facebook#55864)
Summary:
Pull Request resolved: facebook#55864
X-link: facebook/yoga#1906
Yoga's JavaScript bindings previously used Emscripten embind to bridge
C++ wrapper classes to JavaScript. This added unnecessary overhead and
complexity: JS calls went through embind → C++ wrapper classes (Node.cpp,
Config.cpp) → Yoga C API, requiring the embind runtime to be bundled into
the WASM output.
This diff removes embind entirely. JavaScript now calls Yoga's C API
directly, with a thin C bridge (wasm_bridge.c, ~140 lines) handling only
what raw C exports cannot:
- Struct returns (YGValue) via a static buffer read through HEAPF32/HEAP32
- Measure/dirtied callbacks via EM_JS dispatching to JS-side Maps
The JS side (wrapAssembly.ts) is rewritten to use classes (NodeImpl,
ConfigImpl) that store a WASM pointer and call C functions directly via
`lib._YGFunctionName()`. Tree hierarchy (children/parent) is tracked
entirely in JS, matching the pattern used by the Java JNI bindings.
The public API shape (Yoga, Node, Config types) remains identical.
**Bundle size (SINGLE_FILE base64-embedded WASM):**
| Metric | Before (embind) | After (direct C) | Change |
|---|---|---|---|
| Raw | 126,288 B | 115,370 B | -8.6% |
| Gzip | 51,042 B | 42,764 B | -16.2% |
**Benchmark results (median of 3 runs):**
| Benchmark | Before | After | Change |
|---|---|---|---|
| Stack with flex | 20ms | 8ms | 2.5x faster |
| Align stretch in undefined axis | 19ms | 5ms | 3.8x faster |
| Nested flex | 17ms | 4ms | 4.3x faster |
| Huge nested layout | 18ms | 5ms | 3.6x faster |
Fixes facebook/yoga#1545
Changelog: [Internal]
Reviewed By: elicwhite
Differential Revision: D95011356
fbshipit-source-id: a936a9e6705aebe66bf7515ccd67cdc0f55ccae21 parent 4b1dc68 commit 3a8c8a9
1 file changed
+2
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
0 commit comments