Remove embind from Yoga JavaScript bindings#1906
Closed
NickGerleman wants to merge 1 commit intofacebook:mainfrom
Closed
Remove embind from Yoga JavaScript bindings#1906NickGerleman wants to merge 1 commit intofacebook:mainfrom
NickGerleman wants to merge 1 commit intofacebook:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@NickGerleman has exported this pull request. If you are a Meta employee, you can view the originating Diff in D95011356. |
NickGerleman
added a commit
to NickGerleman/react-native
that referenced
this pull request
Mar 3, 2026
Summary: 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. To avoid maintaining a hardcoded EXPORTED_FUNCTIONS list, YG_EXPORT is extended on Emscripten to include `__attribute__((used))` (matching EMSCRIPTEN_KEEPALIVE). Combined with `-fvisibility=hidden` and `--export-dynamic`, this ensures all public Yoga C API functions are automatically exported from WASM — no manual list needed. The closure compiler is retained for JS glue minification. 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 Differential Revision: D95011356
NickGerleman
added a commit
to NickGerleman/yoga
that referenced
this pull request
Mar 3, 2026
Summary: X-link: facebook/react-native#55864 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#1545 Differential Revision: D95011356
Contributor
Author
|
FYI @intergalacticspacehighway @nicoburns This is the version of Yoga Claude Code uses 😅 |
NickGerleman
added a commit
to NickGerleman/react-native
that referenced
this pull request
Mar 5, 2026
Summary: 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
NickGerleman
added a commit
to NickGerleman/yoga
that referenced
this pull request
Mar 5, 2026
Summary: X-link: facebook/react-native#55864 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#1545 Changelog: [Internal] Reviewed By: elicwhite Differential Revision: D95011356
Summary: X-link: facebook/react-native#55864 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#1545 Changelog: [Internal] Reviewed By: elicwhite Differential Revision: D95011356
589446c to
aaaee23
Compare
|
This pull request has been merged in 5ea3509. |
meta-codesync Bot
pushed a commit
to facebook/react-native
that referenced
this pull request
Mar 5, 2026
Summary: Pull Request resolved: #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: a936a9e6705aebe66bf7515ccd67cdc0f55ccae2
zoontek
pushed a commit
to zoontek/react-native
that referenced
this pull request
Mar 9, 2026
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: a936a9e6705aebe66bf7515ccd67cdc0f55ccae2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
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:
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 trackedentirely in JS, matching the pattern used by the Java JNI bindings.
To avoid maintaining a hardcoded EXPORTED_FUNCTIONS list, YG_EXPORT is
extended on Emscripten to include
__attribute__((used))(matchingEMSCRIPTEN_KEEPALIVE). Combined with
-fvisibility=hiddenand--export-dynamic, this ensures all public Yoga C API functions areautomatically exported from WASM — no manual list needed. The closure
compiler is retained for JS glue minification.
The public API shape (Yoga, Node, Config types) remains identical.
Bundle size (SINGLE_FILE base64-embedded WASM):
Benchmark results (median of 3 runs):
Fixes #1545
Differential Revision: D95011356