Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

[skwasm] Dynamic Threading#164748

Merged
auto-submit[bot] merged 8 commits intoflutter:masterfrom
eyebrowsoffire:skwasm_dynamic_threading
Mar 10, 2025
Merged

[skwasm] Dynamic Threading#164748
auto-submit[bot] merged 8 commits intoflutter:masterfrom
eyebrowsoffire:skwasm_dynamic_threading

Conversation

@eyebrowsoffire
Copy link
Contributor

This switches skwasm over from the emscripten pthreads implementation to emscripten's "wasm workers" threading implementation. The pthreads implementation simply will not run at all in a non-crossOriginIsolated context, but the wasm workers implementation only fails if we actually attempt to spawn a thread. This means we can actually choose whether to use a single-threaded or multi-threaded strategy at runtime, which means we don't have to build two variants of skwasm for single- vs multi-threaded.

kevmoo, parlough, bivens-dev, mdebbar, and dxvid-pts reacted with hooray emoji
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel inDiscord (don't just cc them here, they won't see it!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself,is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read theTree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, soall reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actionsgithub-actionsbot added engineflutter/engine related. See also e: labels. platform-webWeb applications specifically labelsMar 6, 2025
@eyebrowsoffire
Copy link
ContributorAuthor

This change doesn't require additional unit tests, because there is no change in functionality. The existing unit tests should be sufficient to confirm that we didn't break any existing functionality with this change.

const url = resolveUrlWithSegments(baseUrl, filename);
return URL.createObjectURL(new Blob(
[`
"use strict";
Copy link
Contributor

Choose a reason for hiding this comment

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

I see randomly missing spaces, e.g. sometimes it'sa = b but sometimesa=b, or) => { vs)=>{, etc. Is that to save over-the-wire payload size, or just hand-formatting errors?

eyebrowsoffire reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah, I took the original file generated by emscripten and modified it until I got it working properly, and then forgot to go back and clean it up (remove debug print statements, use consistent spacing andconst and stuff). So I need to go back and clean this up.

const pendingMessages = [];
const d = message.data;
d["instantiateWasm"] = (info,receiveInstance) => {
var instance=new WebAssembly.Instance(d["wasm"],info);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks likeinstance can beconst.

eyebrowsoffire reacted with thumbs up emoji
console.log("adding queuing listener");
addEventListener("message", eventListener);
};
console.log("adding initial listener");
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how useful theconsole.logs are to the user. This will generate a lot of noise.

eyebrowsoffire reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

We should avoid noise here except in exceptional cases – or for time-bound debugging on our side.

assert(emscripten_is_main_browser_thread());

_thread = emscripten_malloc_wasm_worker(65536);
emscripten_wasm_worker_post_function_v(_thread, []() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, how does this work? Line 22 assertsemscripten_is_main_browser_thread(), which means the worker doesn't execute this code. If so, then the worker doesn't have this closure that's supposed to connect to the main thread. Is this some emscripten magic? 🤔

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah I can break down how this works. So this C++ lambda is not actually a closure, since it doesn't actually close over any variables (there are no captures). As such, a stateless lambda with no closures is special-cased in C++, and it decays to a normal vanilla C function pointer. So if this lambda did capture any variables, this wouldn't work at all, the lambda wouldn't be able to decay to a C function pointer. But with no captures, you can essentially think of the compiler just treating it as a scoped static C function.

Theemscripten_wasm_worker_post_function_v takes a pointer to a C function as an argument. Whenever the address of a function is taken, emscripten/llvm know to add that function to the global function table, and the pointer to that C function is essentially just an index into that global function table. The emscripten wasm workers runtime has JS support code that basically takes this function index and ships it across to the worker via apostMessage. When the worker processes this message, it looks up the function in its own global function table by index, and the global function tables should be identical between the instance on the main thread and the instance on the worker.

@eyebrowsoffireeyebrowsoffire added the autosubmitMerge PR when tree becomes green via auto submit App labelMar 10, 2025
@auto-submitauto-submitbot added this pull request to themerge queueMar 10, 2025
Merged via the queue intoflutter:master with commitb2a4a05Mar 10, 2025
174 of 175 checks passed
@flutter-dashboardflutter-dashboardbot removed the autosubmitMerge PR when tree becomes green via auto submit App labelMar 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 26, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMar 28, 2025
eyebrowsoffire added a commit to eyebrowsoffire/flutter that referenced this pull requestApr 2, 2025
This is a reland offlutter#164748, which wasreverted here:flutter#165350It was reverted due to some issues in the flutter packages roller:flutter#165347The unit test in flutter/packages was modified to be more deterministic and less affected by minor timing differences:flutter/packages#8920So this is basically being relanded without any significant changes, since the downstream tests have been fixed.
github-merge-queuebot pushed a commit that referenced this pull requestApr 2, 2025
This is a reland of#164748,which was reverted here:#165350It was reverted due to some issues in the flutter packages roller:#165347The unit test in flutter/packages was modified to be more deterministicand less affected by minor timing differences:flutter/packages#8920So this is basically being relanded without any significant changes,since the downstream tests have been fixed.
eyebrowsoffire added a commit to eyebrowsoffire/flutter that referenced this pull requestApr 5, 2025
This is a reland offlutter#164748, which wasreverted here:flutter#165350It was reverted due to some issues in the flutter packages roller:flutter#165347The unit test in flutter/packages was modified to be more deterministic and less affected by minor timing differences:flutter/packages#8920So this is basically being relanded without any significant changes, since the downstream tests have been fixed.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMay 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMay 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull requestMay 21, 2025
zhangyuang pushed a commit to zhangyuang/flutter-fork that referenced this pull requestJun 9, 2025
This is a reland offlutter#164748,which was reverted here:flutter#165350It was reverted due to some issues in the flutter packages roller:flutter#165347The unit test in flutter/packages was modified to be more deterministicand less affected by minor timing differences:flutter/packages#8920So this is basically being relanded without any significant changes,since the downstream tests have been fixed.
romanejaquez pushed a commit to romanejaquez/flutter that referenced this pull requestAug 14, 2025
This switches skwasm over from the emscripten pthreads implementation toemscripten's "wasm workers" threading implementation. The pthreadsimplementation simply will not run at all in a non-crossOriginIsolatedcontext, but the wasm workers implementation only fails if we actuallyattempt to spawn a thread. This means we can actually choose whether touse a single-threaded or multi-threaded strategy at runtime, which meanswe don't have to build two variants of skwasm for single- vsmulti-threaded.
romanejaquez pushed a commit to romanejaquez/flutter that referenced this pull requestAug 14, 2025
This reverts commitb2a4a05.This has been causing issues when rolling to flutter/packages repo. Seeflutter#165347.
romanejaquez pushed a commit to romanejaquez/flutter that referenced this pull requestAug 14, 2025
This is a reland offlutter#164748,which was reverted here:flutter#165350It was reverted due to some issues in the flutter packages roller:flutter#165347The unit test in flutter/packages was modified to be more deterministicand less affected by minor timing differences:flutter/packages#8920So this is basically being relanded without any significant changes,since the downstream tests have been fixed.
@eyebrowsoffireeyebrowsoffire deleted the skwasm_dynamic_threading branchDecember 12, 2025 21:52
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@kevmookevmookevmoo left review comments

@yjbanovyjbanovyjbanov approved these changes

Assignees

No one assigned

Labels

engineflutter/engine related. See also e: labels.platform-webWeb applications specifically

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@eyebrowsoffire@kevmoo@yjbanov

[8]ページ先頭

©2009-2026 Movatter.jp