-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Slimmer QueueUserWorkItemCallback #3157
Conversation
@@ -53,7 +53,7 @@ internal void Undo() | |||
|
|||
public sealed class ExecutionContext : IDisposable | |||
{ | |||
private static readonly ExecutionContext Default = new ExecutionContext(); | |||
internal static readonly ExecutionContext Default = new ExecutionContext(); |
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.
This can stay private and you can instead use IsDefaultFTContext
Edit: Nevermind, it would need to be internal to be used explicitly as an arg to ExecutionContext.Run.
cc: @ericeil |
QueueUserWorkItemCallback tpcallBack = new QueueUserWorkItemCallback(callBack, state, compressStack, ref stackMark); | ||
ExecutionContext context = compressStack && !ExecutionContext.IsFlowSuppressed() ? | ||
ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase) : | ||
ExecutionContext.Default; |
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.
@ericeil should comment on whether for this version of the code base it needs to be this complicated, or whether for CoreCLR it could be simplified, since we know that many of these things are nops.
3645744
to
afe2dc4
Compare
@@ -1168,11 +1168,7 @@ internal interface IThreadPoolWorkItem | |||
|
|||
internal sealed class QueueUserWorkItemCallback : IThreadPoolWorkItem |
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.
Please rename to QueueUserWorkItemCallbackNullContext
A couple of general thoughts on this:
Overall, though, I think this is a great change to try, with potential to help substantially in many scenarios. |
cc: @kouvel |
Thanks Eric! At the ICorDebug interfaces our interaction with the threadpool is identifying which threads are in the pool so no worries there. The SOS/DAC interfaces expose data from ThreadpoolMgr native class, but I am guessing this change wouldn't affect it. The relevant source is debug\daccess\request.cpp ClrDataAccess::GetThreadpoolData(struct DacpThreadpoolData *threadpoolData). Higher up the stack its possible that Visual Studio might introspect on those types, but a cursory source search didn't find anything. I'll send an email to the VS debugger guys and ask them to take a peak. |
16e65e5
to
b939185
Compare
Altered to follow @stephentoub's suggestion of having the null context use the same as non default context, and do the null check in execute. So there is just one new type for the default context. Both null and non-default context now use the original type which is more or less the same other than removing the constructor that does the EC capture. |
Following up, my coworker over in VS debugger wrote me back and said he thinks this is fine from the VS perspective, they don't introspect into these types. |
// call directly if it is an unsafe call OR EC flow is suppressed | ||
WaitCallback cb = callback; | ||
callback = null; | ||
cb(state); |
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 did you swap the polarity of the if/else?
Thanks, @noahfalk, for following up. |
LGTM (once squashed). Does this have the expected impact on your benchmark? |
672e93a
to
9418bc4
Compare
Checking now |
Looks great. Thanks! |
Slimmer QueueUserWorkItemCallback
Very cool 👍 |
@geoffkizer we should get some updated numbers soon. |
As per https://github.com/dotnet/coreclr/issues/3147#issuecomment-183158977
No stored
ExecutionContext
when context is default/cc @stephentoub something like this?