Skip to content

Commit bde0dad

Browse files
authored
[wasm] Set flutter_runtime_mode in tools/gn to_gn_wasm_args (flutter#193407)
### Rationale In `engine/src/flutter/tools/gn`, `to_gn_args()` checks `if args.target_os == 'wasm' or args.web:`, delegates to `to_gn_wasm_args()`, and returns early before reaching the line `gn_args['flutter_runtime_mode'] = runtime_mode`. Because `to_gn_wasm_args()` never mapped the argument back into `gn_args`, `flutter_runtime_mode` falls back to `"debug"` during GN evaluation for all `--web` engine targets. This evaluates `impeller_debug = true` (`IMPELLER_DEBUG=1` macro) globally in C++ for Web Impeller release builds. This defect was driving 50+ synchronous `glCheckFramebufferStatus()` calls per frame on `bouncy@128` (and 500+ calls per frame on multi-pass blur/filter workloads) during Web Impeller benchmarking. ### Summary of Changes - Propagates `args.runtime_mode` into `gn_args['flutter_runtime_mode']` inside `to_gn_wasm_args()` in `tools/gn`. - Adds explicit unit tests in `tools/gn_test.py` (`test_get_out_dir` and `test_to_gn_args`) verifying `flutter_runtime_mode` and output directories across `debug`, `profile`, and `release` for `--web` and `--target-os=wasm`. ### Verification & Empirical Performance Delta (`wimp.wasm` `wasm_release`) - Executed `tools/gn_test.py` with 100% pass on all 5 test cases. - Built `wimp.wasm` (`wasm_release`) locally before and after this change and benchmarked both single-pass and multi-pass offscreen workloads (`?effects=multipass`, wrapping each leaf node in `ColorFiltered` + `ClipRect` + `BackdropFilter` 5px Gaussian blur + `Opacity`): | Workload & Metric | Before (`IMPELLER_DEBUG=1`) | After (`IMPELLER_DEBUG=0`) | Delta | Speedup | | :--- | :---: | :---: | :---: | :---: | | **`wimp.wasm` Uncompressed / Gzipped Size** | `3,608,411 B` / `1,463,726 B` | `3,599,401 B` / `1,457,944 B` | `-9,010 B` / `-5,782 B` | `-0.25%` / `-0.40%` | | **`bouncy@128` (single-pass) `glCheckFramebufferStatus` / frame** | `58` (`2.83%` worker CPU) | `0` | **`-100.0%`** | Eliminated | | **`bouncy_multipass@16` (`wimp_st`) `glCheckFramebufferStatus` / frame** | `148` | `0` | **`-100.0%`** | Eliminated | | **`bouncy_multipass@16` (`wimp_st`) Raster Time (`ms/frame`)** | `273.40 ms` | `210.28 ms` | **`-63.12 ms` (`-23.1%`)** | **`1.30x` faster** | | **`bouncy_multipass@32` (`wimp_st`) `glCheckFramebufferStatus` / frame** | `268` | `0` | **`-100.0%`** | Eliminated | | **`bouncy_multipass@32` (`wimp_st`) Raster Time (`ms/frame`)** | `286.61 ms` | `203.44 ms` | **`-83.16 ms` (`-29.0%`)** | **`1.41x` faster** | | **`bouncy_multipass@64` (`wimp_st`) `glCheckFramebufferStatus` / frame** | `502` | `0` | **`-100.0%`** | Eliminated | | **`bouncy_multipass@64` (`wimp_st`) Raster Time (`ms/frame`)** | `364.64 ms` | `246.61 ms` | **`-118.03 ms` (`-32.4%`)** | **`1.48x` faster** | | **`bouncy_multipass@64` (`wimp_mt`) `glCheckFramebufferStatus` / frame** | `503` | `0` | **`-100.0%`** | Eliminated | | **`bouncy_multipass@64` (`wimp_mt`) Raster Time (`ms/frame`)** | `380.41 ms` | `256.95 ms` | **`-123.46 ms` (`-32.5%`)** | **`1.48x` faster** | | **`bouncy_multipass@64` (`--disable-gl-drawing-for-tests`, `wimp_st`)** | `228.21 ms` | `42.31 ms` | **`-185.90 ms` (`-81.5%`)** | **`5.39x` faster** | Fixes flutter#193406 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 569d975 commit bde0dad

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎engine/src/flutter/tools/gn‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ def to_gn_wasm_args(args, gn_args):
891891
gn_args['skia_canvaskit_enable_webgl'] = True
892892
gn_args['skia_canvaskit_enable_webgpu'] = False
893893
gn_args['skia_canvaskit_profile_build'] = args.runtime_mode == 'profile'
894+
gn_args['flutter_runtime_mode'] = args.runtime_mode
894895
gn_args['flutter_prebuilt_dart_sdk'] = True
895896

896897
if get_host_os() == 'mac':

‎engine/src/flutter/tools/gn_test.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ def test_get_out_dir(self):
2929
self._expect_build_dir(['--android'], os.path.join('out', 'android_debug'))
3030
self._expect_build_dir(['--android', '--runtime-mode', 'release'],
3131
os.path.join('out', 'android_release'))
32+
self._expect_build_dir(['--web'], os.path.join('out', 'wasm_debug'))
33+
self._expect_build_dir(['--web', '--runtime-mode', 'profile'],
34+
os.path.join('out', 'wasm_profile'))
35+
self._expect_build_dir(['--web', '--runtime-mode', 'release'],
36+
os.path.join('out', 'wasm_release'))
3237

3338
def _gn_args(self, arg_list):
3439
args = gn.parse_args(['gn'] + arg_list)
@@ -40,6 +45,17 @@ def test_to_gn_args(self):
4045
self._gn_args(['--ios', '--simulator', '--simulator-cpu', 'x64'])['target_cpu'], 'x64'
4146
)
4247
self.assertEqual(self._gn_args(['--ios'])['target_cpu'], 'arm64')
48+
self.assertEqual(self._gn_args(['--web'])['flutter_runtime_mode'], 'debug')
49+
self.assertEqual(
50+
self._gn_args(['--web', '--runtime-mode', 'profile'])['flutter_runtime_mode'], 'profile'
51+
)
52+
self.assertEqual(
53+
self._gn_args(['--web', '--runtime-mode', 'release'])['flutter_runtime_mode'], 'release'
54+
)
55+
self.assertEqual(
56+
self._gn_args(['--target-os', 'wasm', '--runtime-mode', 'release'])['flutter_runtime_mode'],
57+
'release'
58+
)
4359

4460
def test_cannot_use_android_and_enable_unittests(self):
4561
with self.assertRaises(Exception):

0 commit comments

Comments
 (0)