Update Emscripten SDK from 3.1.28 to 4.0.23#1907
Closed
NickGerleman wants to merge 2 commits into
Closed
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 D95012856. |
cortinico
approved these changes
Mar 3, 2026
cortinico
left a comment
Contributor
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
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: - 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 react#1545 Differential Revision: D95011356
NickGerleman
added a commit
to NickGerleman/yoga
that referenced
this pull request
Mar 5, 2026
Summary: Update the Emscripten SDK used for the JavaScript WASM build from 3.1.28 to 4.0.23. This brings ~2 years of Emscripten improvements including better WASM codegen and smaller JS glue output. Required build config changes for Emscripten 4.x compatibility: - Remove `--memory-init-file 0` (deprecated, no longer accepted) - Change `TEXTDECODER=0` to `TEXTDECODER=2` (0 is no longer valid) - Add `EXPORTED_RUNTIME_METHODS=['HEAPF32','HEAP32']` (heap views are no longer on Module by default in 4.x) **Bundle size:** | Metric | emsdk 3.1.28 | emsdk 4.0.23 | Change | |---|---|---|---| | Raw | 115,370 B | 90,219 B | -21.8% | | Gzip | 42,764 B | 34,445 B | -19.4% | **Benchmark results (median of 3 runs):** | Benchmark | 3.1.28 | 4.0.23 | Change | |---|---|---|---| | Stack with flex | 9ms | 6ms | similar | | Align stretch | 5ms | 4ms | similar | | Nested flex | 4ms | 4ms | same | | Huge nested layout | 5ms | 4ms | similar | Reviewed By: cortinico Differential Revision: D95012856
91b4481 to
9628d56
Compare
NickGerleman
added a commit
to NickGerleman/yoga
that referenced
this pull request
Mar 5, 2026
Summary: Update the Emscripten SDK used for the JavaScript WASM build from 3.1.28 to 4.0.23. This brings ~2 years of Emscripten improvements including better WASM codegen and smaller JS glue output. Required build config changes for Emscripten 4.x compatibility: - Remove `--memory-init-file 0` (deprecated, no longer accepted) - Change `TEXTDECODER=0` to `TEXTDECODER=2` (0 is no longer valid) - Add `EXPORTED_RUNTIME_METHODS=['HEAPF32','HEAP32']` (heap views are no longer on Module by default in 4.x) **Bundle size:** | Metric | emsdk 3.1.28 | emsdk 4.0.23 | Change | |---|---|---|---| | Raw | 115,370 B | 90,219 B | -21.8% | | Gzip | 42,764 B | 34,445 B | -19.4% | **Benchmark results (median of 3 runs):** | Benchmark | 3.1.28 | 4.0.23 | Change | |---|---|---|---| | Stack with flex | 9ms | 6ms | similar | | Align stretch | 5ms | 4ms | similar | | Nested flex | 4ms | 4ms | same | | Huge nested layout | 5ms | 4ms | similar | Reviewed By: cortinico Differential Revision: D95012856
9628d56 to
3952b86
Compare
Summary: Pull Request resolved: react#1907 Update the Emscripten SDK used for the JavaScript WASM build from 3.1.28 to 4.0.23. This brings ~2 years of Emscripten improvements including better WASM codegen and smaller JS glue output. Required build config changes for Emscripten 4.x compatibility: - Remove `--memory-init-file 0` (deprecated, no longer accepted) - Change `TEXTDECODER=0` to `TEXTDECODER=2` (0 is no longer valid) - Add `EXPORTED_RUNTIME_METHODS=['HEAPF32','HEAP32']` (heap views are no longer on Module by default in 4.x) **Bundle size:** | Metric | emsdk 3.1.28 | emsdk 4.0.23 | Change | |---|---|---|---| | Raw | 115,370 B | 90,219 B | -21.8% | | Gzip | 42,764 B | 34,445 B | -19.4% | **Benchmark results (median of 3 runs):** | Benchmark | 3.1.28 | 4.0.23 | Change | |---|---|---|---| | Stack with flex | 9ms | 6ms | similar | | Align stretch | 5ms | 4ms | similar | | Nested flex | 4ms | 4ms | same | | Huge nested layout | 5ms | 4ms | similar | Reviewed By: cortinico Differential Revision: D95012856
3952b86 to
0da4a9e
Compare
|
This pull request has been merged in 8d88a4a. |
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:
Update the Emscripten SDK used for the JavaScript WASM build from
3.1.28 to 4.0.23. This brings ~2 years of Emscripten improvements
including better WASM codegen and smaller JS glue output.
Required build config changes for Emscripten 4.x compatibility:
--memory-init-file 0(deprecated, no longer accepted)TEXTDECODER=0toTEXTDECODER=2(0 is no longer valid)EXPORTED_RUNTIME_METHODS=['HEAPF32','HEAP32'](heap views areno longer on Module by default in 4.x)
Bundle size:
Benchmark results (median of 3 runs):
Differential Revision: D95012856