Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@eyebrowsoffire
Copy link
Contributor

@eyebrowsoffire eyebrowsoffire commented Oct 29, 2024

This PR creates a single-threaded version of the skwasm renderer, appropriate for non-crossOriginIsolated browsing contexts.

  • The single threaded renderer is essentially the same as the multi-threaded renderer, except instead of spawning a web worker and posting messages to it, it simply schedules microtasks on the main thread in their place.
  • The new renderer is vended as skwasm_st.js and skwasm_st.wasm in the same location as multithreaded skwasm. In order to properly build and function, we needed some fixes I put into emscripten that landed in version 3.1.70. That version also changed some behavior that required a few fixes to the CanvasKit build files.
  • The skwasm loader in flutter.js has been modified to use the skwasm_st variants when encountering a non-crossOriginIsolated context but a browser and configuration that otherwise would allow the use of skwasm. I also added a new forceSingleThreadedSkwasm option to the flutter configuration so that we can override this behavior, especially so that we can accurately benchmark the single threaded renderer in a crossOriginIsolated environment.
  • I also consolidated a bunch of our shards that run tests to just have one per browser/platform combination, so four total. This will address Web tests may be too sharded flutter#124682

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Oct 29, 2024
@eyebrowsoffire eyebrowsoffire marked this pull request as ready for review October 30, 2024 00:07
Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a couple questions

);

if (await _checkSkiaClient(skiaClient)) {
print('Successfully checked Skia Gold Client');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these leftover debug prints or are they intended to be part of the output (e.g. to help debug flaky tests on CI)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found them actually kind of useful enough to leave in. They only are printed once for each suite when they run, so they aren't particularly chatty. If you don't like them in here I can remove them, but it's actually nice to be able to make sure we created a skia gold client with the right dimensions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to keep in, then.

@eyebrowsoffire eyebrowsoffire added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 31, 2024
@jonahwilliams
Copy link
Contributor

reason for revert: failing to roll into framework: flutter/flutter#157919

@jonahwilliams jonahwilliams added the revert Label used to revert changes in a closed and merged pull request. label Oct 31, 2024
auto-submit bot pushed a commit that referenced this pull request Oct 31, 2024
@auto-submit auto-submit bot removed the revert Label used to revert changes in a closed and merged pull request. label Oct 31, 2024
auto-submit bot added a commit that referenced this pull request Oct 31, 2024
Reverts: #56206
Initiated by: jonahwilliams
Reason for reverting: failing to roll into framework: flutter/flutter#157919 
Original PR Author: eyebrowsoffire

Reviewed By: {harryterkelsen}

This change reverts the following previous change:
This PR creates a single-threaded version of the skwasm renderer, appropriate for non-crossOriginIsolated browsing contexts.
* The single threaded renderer is essentially the same as the multi-threaded renderer, except instead of spawning a web worker and posting messages to it, it simply schedules microtasks on the main thread in their place.
* The new renderer is vended as `skwasm_st.js` and `skwasm_st.wasm` in the same location as multithreaded skwasm. In order to properly build and function, we needed some fixes I put into emscripten that landed in version 3.1.70. That version also changed some behavior that required a few fixes to the CanvasKit build files.
* The skwasm loader in flutter.js has been modified to use the skwasm_st variants when encountering a non-crossOriginIsolated context but a browser and configuration that otherwise would allow the use of skwasm. I also added a new `forceSingleThreadedSkwasm` option to the flutter configuration so that we can override this behavior, especially so that we can accurately benchmark the single threaded renderer in a crossOriginIsolated environment.
* I also consolidated a bunch of our shards that run tests to just have one per browser/platform combination, so four total. This will address flutter/flutter#124682
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 31, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 31, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 31, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Oct 31, 2024
…157926)

flutter/engine@c40b0b6...f2154ef

2024-10-31 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Skwasm single threaded (#56206)" (flutter/engine#56264)
2024-10-31 [email protected] Roll Skia from 4f8f2ecadfb6 to 3c628426f85f (1 revision) (flutter/engine#56261)
2024-10-31 [email protected] Roll Skia from 7e79a516284b to 4f8f2ecadfb6 (1 revision) (flutter/engine#56255)
2024-10-31 [email protected] Roll Dart SDK from 6a8058eef22c to f3e3dc44b1dc (1 revision) (flutter/engine#56253)
2024-10-31 [email protected] Roll Skia from 3c62d4a94d78 to 7e79a516284b (1 revision) (flutter/engine#56252)
2024-10-31 [email protected] [Impeller] use primitive restart for faster tessellation: write directly into host buffer. (flutter/engine#56173)
2024-10-31 [email protected] Skwasm single threaded (flutter/engine#56206)
2024-10-31 [email protected] [Impeller] expose reference to tessellator instead of shared_ptr. (flutter/engine#56244)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
eyebrowsoffire added a commit to eyebrowsoffire/engine that referenced this pull request Oct 31, 2024
auto-submit bot pushed a commit that referenced this pull request Nov 1, 2024
This attempts to reland the single-threaded Skwasm PR: #56206

The main changes here are in the second commit:
* We need to actually bundle the `skwasm_st` artifacts in `flutter_web_sdk.zip`
* The `locateFile` hack no longer works since emscripten doesn't actually create a worker.js file anymore. So instead, that has been modified to use the `mainScriptUrlOrBlob` module API to do a very similar hack.

Note: I did presubmit testing with the framework CI and it appears the pertinent tests pass. See flutter/flutter#157967
@brian-superlist
Copy link

brian-superlist commented Nov 3, 2024

Heya, very cool work! I was trying this out, but ran into the following error and the web app doesn't load for me.

What I tried:

  • Upgrading to Flutter/master with this engine roll in place
  • Build our web app, adding the forceSingleThreadedSkwasm to the _flutter.loader.load({config: {forceSingleThreadedSkwasm: true} to ensure we're running in single threaded mode. Command used: flutter build web --release --csp --source-maps --target lib/main_dev.dart --wasm --no-strip-wasm
  • Ran the web app with dhttpd: dart pub global run dhttpd --path build/web
  • Open localhost:8080 in Chrome Version 130.0.6723.70 (Official Build) (arm64)
  • I can confirm that it's loading the wasm files (main.dart.wasm in the sources panel of the Chrome Dev Tools)
  • I see it also loading the new skwasm_st.js from https://www.gstatic.com/flutter-canvaskit/05cb5d7f7939da58ef9897997004f181f2699075/skwasm_st.js

The following error is thrown:

Dart stack trace:
    at module0.initializeEngineServices closure initializeRendererCallback at org-dartlang-sdk:///lib/_engine/engine/initialization.dart:196:43 inner (initialization.dart:196:43)
    at module0.initializeEngineServices inner (initialization.dart:196:43)
    at module0.bootstrapEngine closure at org-dartlang-sdk:///lib/ui_web/ui_web/initialization.dart:33:23 inner (initialization.dart:110:14)
    at module0.bootstrapEngine closure at org-dartlang-sdk:///lib/ui_web/ui_web/initialization.dart:33:23 (initialization.dart:33:23)
    at module0.closure wrapper at org-dartlang-sdk:///lib/ui_web/ui_web/initialization.dart:33:23 trampoline_118538 (main.dart.wasm:0x979589)
    at module0.AppBootstrap.prepareEngineInitializer closure at org-dartlang-sdk:///lib/_engine/engine/app_bootstrap.dart:47:25 inner (app_bootstrap.dart:48:32)
    at module0.AppBootstrap.prepareEngineInitializer closure at org-dartlang-sdk:///lib/_engine/engine/app_bootstrap.dart:47:25 (app_bootstrap.dart:47:25)
    at module0.closure wrapper at org-dartlang-sdk:///lib/_engine/engine/app_bootstrap.dart:47:25 trampoline_118554 (main.dart.wasm:0x97968c)
    at module0.initializeEngineServices closure initializeRendererCallback at org-dartlang-sdk:///lib/_engine/engine/initialization.dart:196:43 inner (initialization.dart:196:43)
    at module0.initializeEngineServices inner (initialization.dart:196:43)
    at module0.bootstrapEngine closure at org-dartlang-sdk:///lib/ui_web/ui_web/initialization.dart:33:23 inner (initialization.dart:110:14)
    at module0.bootstrapEngine closure at org-dartlang-sdk:///lib/ui_web/ui_web/initialization.dart:33:23 (initialization.dart:33:23)
    at module0.closure wrapper at org-dartlang-sdk:///lib/ui_web/ui_web/initialization.dart:33:23 trampoline_118538 (main.dart.wasm:0x979589)
    at module0.AppBootstrap.prepareEngineInitializer closure at org-dartlang-sdk:///lib/_engine/engine/app_bootstrap.dart:47:25 inner (app_bootstrap.dart:48:32)
    at module0.AppBootstrap.prepareEngineInitializer closure at org-dartlang-sdk:///lib/_engine/engine/app_bootstrap.dart:47:25 (app_bootstrap.dart:47:25)
    at module0.closure wrapper at org-dartlang-sdk:///lib/_engine/engine/app_bootstrap.dart:47:25 trampoline_118554 (main.dart.wasm:0x97968c)
    at _2868 (main.dart.mjs:1286:16)
    at module0.JSFunctionUnsafeUtilExtension|callAsConstructor (js_interop_unsafe_patch.dart:61:22)
    at module0.CustomFutureOfJSAnyToJSPromise|get#toPromise closure at org-dartlang-sdk:///lib/_engine/engine/js_interop/js_promise.dart:18:19 (js_promise.dart:27:30)
    at module0.closure wrapper at org-dartlang-sdk:///lib/_engine/engine/js_interop/js_promise.dart:18:19 trampoline (main.dart.wasm:0x979d49)
    at module0._RootZone.runBinary (zone.dart:1681:54)
    at module0._Future._propagateToListeners (future_impl.dart:219:22)
    at module0._Future._completeError (future_impl.dart:711:5)
    at module0._Future._asyncCompleteError closure at org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart:796:29 (future_impl.dart:797:7)
    at module0.closure wrapper at org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart:796:29 trampoline (main.dart.wasm:0x38b771)
    at module0._startMicrotaskLoop (schedule_microtask.dart:40:21)

I've also sent an email with some of this info to @kevmoo since he's been coordinating with us to get our app running with WASM, but I thought I'd put more info here.

I'm excited to get WASM going! So far, we've seen some big performance improvements with the multi-threaded renderer, but we have some use cases which don't work with the restrictive COEP & COOP headers. Thanks for all the effort.

Could this be related to this part of your comment?

In order to properly build and function, we needed some fixes I put into emscripten that landed in version 3.1.70. That version also changed some behavior that required a few fixes to the CanvasKit build files.

@brian-superlist
Copy link

Ah wait, my bad -- I looked at the project code for a fresh project vs our custom code we have. We had actually enabled a couple of performance optimizations for firefox with JS, but that was a bad idea with the new wasm renderer.

Apologies for the noise and thanks again for the contribution. Here are the offending lines I had to remove:

window.createImageBitmap = null;
window.OffscreenCanvas = null;

@eyebrowsoffire
Copy link
Contributor Author

@brian-superlist Ah good to hear. Yes the skwasm web renderer requires those APIs so that makes sense. Glad to hear it's working!

nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
This PR creates a single-threaded version of the skwasm renderer, appropriate for non-crossOriginIsolated browsing contexts.
* The single threaded renderer is essentially the same as the multi-threaded renderer, except instead of spawning a web worker and posting messages to it, it simply schedules microtasks on the main thread in their place.
* The new renderer is vended as `skwasm_st.js` and `skwasm_st.wasm` in the same location as multithreaded skwasm. In order to properly build and function, we needed some fixes I put into emscripten that landed in version 3.1.70. That version also changed some behavior that required a few fixes to the CanvasKit build files.
* The skwasm loader in flutter.js has been modified to use the skwasm_st variants when encountering a non-crossOriginIsolated context but a browser and configuration that otherwise would allow the use of skwasm. I also added a new `forceSingleThreadedSkwasm` option to the flutter configuration so that we can override this behavior, especially so that we can accurately benchmark the single threaded renderer in a crossOriginIsolated environment.
* I also consolidated a bunch of our shards that run tests to just have one per browser/platform combination, so four total. This will address flutter#124682
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
Reverts: flutter/engine#56206
Initiated by: jonahwilliams
Reason for reverting: failing to roll into framework: flutter#157919 
Original PR Author: eyebrowsoffire

Reviewed By: {harryterkelsen}

This change reverts the following previous change:
This PR creates a single-threaded version of the skwasm renderer, appropriate for non-crossOriginIsolated browsing contexts.
* The single threaded renderer is essentially the same as the multi-threaded renderer, except instead of spawning a web worker and posting messages to it, it simply schedules microtasks on the main thread in their place.
* The new renderer is vended as `skwasm_st.js` and `skwasm_st.wasm` in the same location as multithreaded skwasm. In order to properly build and function, we needed some fixes I put into emscripten that landed in version 3.1.70. That version also changed some behavior that required a few fixes to the CanvasKit build files.
* The skwasm loader in flutter.js has been modified to use the skwasm_st variants when encountering a non-crossOriginIsolated context but a browser and configuration that otherwise would allow the use of skwasm. I also added a new `forceSingleThreadedSkwasm` option to the flutter configuration so that we can override this behavior, especially so that we can accurately benchmark the single threaded renderer in a crossOriginIsolated environment.
* I also consolidated a bunch of our shards that run tests to just have one per browser/platform combination, so four total. This will address flutter#124682
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
This attempts to reland the single-threaded Skwasm PR: flutter/engine#56206

The main changes here are in the second commit:
* We need to actually bundle the `skwasm_st` artifacts in `flutter_web_sdk.zip`
* The `locateFile` hack no longer works since emscripten doesn't actually create a worker.js file anymore. So instead, that has been modified to use the `mainScriptUrlOrBlob` module API to do a very similar hack.

Note: I did presubmit testing with the framework CI and it appears the pertinent tests pass. See flutter#157967
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants