Skip to content

Conversation

@pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Jan 18, 2026

For single-threaded Browser runtime we already

  • don't use ConcurrentQueue in ThreadPoolWorkQueue
  • or any other items from System.Collections.Concurrent assembly in the CoreLib
    • so that we do not keep those types from trimming. Download size matters.
  • this covers it with System.Runtime.Tests/TrimmingTests/DoesntIncludeConcurentTypes.cs
    • testing that we are trimming those types and whole assembly System.Collections.Concurrent

@pavelsavara pavelsavara added this to the 11.0.0 milestone Jan 18, 2026
@pavelsavara pavelsavara self-assigned this Jan 18, 2026
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-System.Globalization size-reduction Issues impacting final app size primary for size sensitive workloads os-browser Browser variant of arch-wasm labels Jan 18, 2026
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Jan 18, 2026
@jkotas
Copy link
Member

jkotas commented Jan 19, 2026

Do you have any numbers for how much this saves for user apps?

ConcurrentDictionary is used pretty frequently for performance reasons. It is not practical to ifdef out every use of it. If we are not happy about its footprint for single threaded wasm, it may be better to provide an alternative lighter weight implementation instead of trying to ifdef out every use.

cc @stephentoub

@pavelsavara
Copy link
Member Author

I admit that most normal applications would use those data structures.
On the other hand, some customers are very interested in pay for play size and I had to #ifdef only 2 places in corelib.

On the left is the same app with extra

        var x=new System.Collections.Concurrent.ConcurrentDictionary<int, int>();
        x[1] = 1;
        Console.WriteLine(x[1]);
        var y=new System.Collections.Concurrent.ConcurrentBag<int>();
        y.Add(1);
image

The difference is 46kb uncompressed.
Regarding perf I hope that R2R of just normal Dictionary would serve us better than to have 2 code bases.

Anyway, even if we revert most of this, I would like to keep non concurrent Queue in ThreadPoolWorkQueue and cover it with similar trimming test I drafted here.

@jkotas
Copy link
Member

jkotas commented Jan 19, 2026

On the left is the same app with extra

I would like to see number for a Blazor app. (total size / bytes saved by this change)

I had to #ifdef only 2 places in corelib.

Ifdefs like this tend to keep growing to the point of being non-sustainable.

non concurrent Queue in ThreadPoolWorkQueue

That's fine with me. Queue is used a lot less frequently and ThreadPool has a bunch of ifdefs for single-threaded wasm, so one more does not sound like a problem.

@stephentoub
Copy link
Member

I agree if there's a need for something like this, we should instead just have alternate impls of those data structures for the single threaded wasm use. Could be as simple as the public API shimming to a wrapped dictionary/queue.

# Conflicts:
#	src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/BFloat16Tests.cs
@pavelsavara
Copy link
Member Author

I agree if there's a need for something like this, we should instead just have alternate impls of those data structures for the single threaded wasm use. Could be as simple as the public API shimming to a wrapped dictionary/queue.

OK, I reverted the corelib changes and this is only trimming test now

@pavelsavara pavelsavara changed the title [browser][ST] trim ConcurrentDictionary [browser][ST] test trimming of System.Collections.Concurrent Jan 20, 2026
@pavelsavara pavelsavara marked this pull request as ready for review January 20, 2026 19:32
Copilot AI review requested due to automatic review settings January 20, 2026 19:32
Copy link
Contributor

Copilot AI left a 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 adds a trimming test to verify that System.Collections.Concurrent types are not included in trimmed single-threaded Browser runtime builds, reducing download size. The test validates that the CoreLib avoids dependencies on concurrent collections when threads are not enabled.

Changes:

  • Adds a new trimming test that checks concurrent collection types are trimmed from Browser WASM builds
  • Conditionally includes the test only for Browser targets without threading enabled

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
System.Runtime.TrimmingTests.proj Adds conditional inclusion of the new test for single-threaded Browser targets
BrowserDoesNotIncludeConcurrentTypes.cs New test file that verifies concurrent collection types are trimmed from the assembly

pavelsavara and others added 2 commits January 20, 2026 21:00
…ngTests/BrowserDoesNotIncludeConcurrentTypes.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ngTests/BrowserDoesNotIncludeConcurrentTypes.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@pavelsavara
Copy link
Member Author

image

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

(Make sure that the commit description matches the final PR content when merging.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-System.Collections linkable-framework Issues associated with delivering a linker friendly framework os-browser Browser variant of arch-wasm size-reduction Issues impacting final app size primary for size sensitive workloads

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants