-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[browser][ST] IsSingleThreaded and ThrowIfSingleThreaded #123329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR improves trimming for single-threaded (ST) WebAssembly builds by making the trimming work for both CoreCLR and Mono flavors, adding guards to trim code after unsupported blocking operations, and simplifying the ProcessorCount substitution approach.
Changes:
- Replaced ILLink XML substitution for ProcessorCount with inline conditional compilation
- Added FEATURE_SINGLE_THREADED guards before blocking operations to enable better code trimming
- Extended single-threaded support from browser-only to both browser and WASI platforms
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| ILLink.Substitutions.wasm.singlethread.xml | Removed - ProcessorCount substitution now handled inline |
| System.Private.CoreLib.csproj (Mono) | Removed reference to deleted substitution file |
| Parallel.cs | Added FEATURE_SINGLE_THREADED guard before WaitAll blocking operation |
| System.Threading.Tasks.Parallel.csproj | Added FeatureSingleThread property and FEATURE_SINGLE_THREADED define |
| Task.cs | Added guards before blocking wait operations in SpinThenBlockingWait and WaitAnyCore |
| FutureFactory.cs | Added guard before RegisterWaitForSingleObject blocking operation |
| LowLevelLock.cs | Added guard before blocking monitor acquire |
| Environment.cs | Moved ProcessorCount property inside conditional compilation for better trimming |
| NativeRuntimeEventSource.Threading.cs | Added early return for browser in ThreadPoolIOEnqueue |
| NativeRuntimeEventSource.Threading.NativeSinks.cs | Added PlatformNotSupportedException for browser in ThreadPoolIOEnqueue |
| SystemdNotifier.cs | Added IsBrowser check to existing WASI platform check |
| XmlDocumentDecryptor.cs | Added IsBrowser check to existing WASI platform check |
| Thread.CoreCLR.cs | Added early return for browser in SpinWait |
| System.Private.CoreLib.csproj (CoreCLR) | Added feature flags, defines, and browser platform support for CA1416 |
...ate.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.Threading.NativeSinks.cs
Outdated
Show resolved
Hide resolved
jkotas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please share some number for how much this saves?
.../System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.Threading.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLock.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLock.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLock.cs
Outdated
Show resolved
Hide resolved
|
If the goal is to trim the wait subsystem, would it be worthwhile to provide an alternative implementation of the wait subsystem APIs for the single-threaded scenario that throw when they'd need to wait? Then we wouldn't have this complicated dance to avoid rooting the waiting paths. |
|
Here my goal was mostly fail instead of spin-deadlock.
This PR alone would not be enough to cut all calls to all flavors of
This is interesting idea. When we reach the point when we compare size between Net11 Mono vs Net12 CoreCLR, there would be much bigger motivation to work on it. |
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Can you fix this by marking it with |
That didn't help. I also tried Anyway, right now I need it to throw, we can re-focus on trimming later |
src/libraries/System.Collections.Concurrent/tests/BlockingCollectionCancellationTests.cs
Show resolved
Hide resolved
- move ThrowIfSingleThreaded after argument validation and only on actually blocking path
|
/ba-g failure is #123442 |
|
I enabled those as smoke test on CoreCLR/wasm. |
Uh oh!
There was an error while loading. Please reload this page.