Skip to content

Commit 1d27871

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Remove embind from Yoga JavaScript bindings (#55864)
Summary: X-link: react/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 react/yoga#1545 Changelog: [Internal] Reviewed By: elicwhite Differential Revision: D95011356
1 parent a7ad793 commit 1d27871

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

  • packages/react-native/ReactCommon/yoga/yoga

packages/react-native/ReactCommon/yoga/yoga/YGMacros.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
#ifdef _WINDLL
3131
#define YG_EXPORT __declspec(dllexport)
32+
#elif defined(__EMSCRIPTEN__)
33+
#define YG_EXPORT __attribute__((visibility("default"), used))
3234
#elif !defined(_MSC_VER)
3335
#define YG_EXPORT __attribute__((visibility("default")))
3436
#else

0 commit comments

Comments
 (0)