-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[WASM][ST] Use Queue instead of ConcurrentQueue in single-threaded thread pool #111245
base: main
Are you sure you want to change the base?
[WASM][ST] Use Queue instead of ConcurrentQueue in single-threaded thread pool #111245
Conversation
- use Queue instead of ConcurrentQueue in single-threaded thread pool - protect ConcurrentQueue ctor from trimming when used with `JsonSerializer.Deserialize`
src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs
Outdated
Show resolved
Hide resolved
@@ -11,6 +12,7 @@ internal sealed class ConcurrentQueueOfTConverter<TCollection, TElement> | |||
{ | |||
internal override bool CanPopulate => true; | |||
|
|||
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor, typeof(ConcurrentQueue<>))] |
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.
Why is this necessary? We try really hard to not use DynamicDependency
unless it is a last resort.
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.
Until now the runtime itself was using ConcurrentQueue
ctor and so it was never trimmed.
If we want to keep it friction-less this is one option how.
If we are OK to force users to start doing it themself, we could avoid this DynamicDependency.
Obviously only browser/wasi people will be impacted as thread pool on other platforms will keep it alive anyway.
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.
See src\libraries\System.Text.Json\tests\System.Text.Json.Tests\TrimmingTests\StackOrQueueNotRootedTest.cs
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.
Not a big deal, who needs to deserialize into ConcurrentQueue anyway ?
😉
- I can disable this test on the browser.
- Or I can add DynamicDependency in the test, I'm not sure if that would be defeating the test purpose slightly.
I think it's testing trimming of non-generic collections too, which can keep working.
Please let me know @eerhardt, I don't have strong opinion.
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.
I would just work around it in the tests, and not change the product code for it. If you are using the JsonSerializer with trimming/native AOT, the source generator is the only support route.
Motivation: performance and size improvements for single-threaded WASM
Queue
instead ofConcurrentQueue
in single-threaded thread poolJsonSerializer.Deserialize