{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/coreclr/pulls/comments/231663104","pull_request_review_id":172681600,"id":231663104,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMTY2MzEwNA==","diff_hunk":"@@ -293,12 +293,11 @@ internal static void RunInternal<TState>(ExecutionContext executionContext, Cont\n             edi?.Throw();\n         }\n \n-        internal static void RunFromThreadPoolDispatchLoop(ExecutionContext executionContext, ContextCallback callback, object state)\n+        internal static void RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, object state)","path":"src/System.Private.CoreLib/shared/System/Threading/ExecutionContext.cs","position":36,"original_position":5,"commit_id":"a6aa3e22cc20acbac20b8b11ff78a7d3fa405ea6","original_commit_id":"0282db4c65b86709ecc0d5ecd4b6fc667dfeead2","user":{"login":"kouvel","id":13499639,"node_id":"MDQ6VXNlcjEzNDk5NjM5","avatar_url":"https://avatars1.githubusercontent.com/u/13499639?v=4","gravatar_id":"","url":"https://api.github.com/users/kouvel","html_url":"https://github.com/kouvel","followers_url":"https://api.github.com/users/kouvel/followers","following_url":"https://api.github.com/users/kouvel/following{/other_user}","gists_url":"https://api.github.com/users/kouvel/gists{/gist_id}","starred_url":"https://api.github.com/users/kouvel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kouvel/subscriptions","organizations_url":"https://api.github.com/users/kouvel/orgs","repos_url":"https://api.github.com/users/kouvel/repos","events_url":"https://api.github.com/users/kouvel/events{/privacy}","received_events_url":"https://api.github.com/users/kouvel/received_events","type":"User","site_admin":false},"body":"And similarly elsewhere","created_at":"2018-11-07T20:20:54Z","updated_at":"2018-11-07T20:20:55Z","html_url":"https://github.com/dotnet/coreclr/pull/20308#discussion_r231663104","pull_request_url":"https://api.github.com/repos/dotnet/coreclr/pulls/20308","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/dotnet/coreclr/pulls/comments/231663104"},"html":{"href":"https://github.com/dotnet/coreclr/pull/20308#discussion_r231663104"},"pull_request":{"href":"https://api.github.com/repos/dotnet/coreclr/pulls/20308"}},"in_reply_to_id":231663062},"pull_request":{"url":"https://api.github.com/repos/dotnet/coreclr/pulls/20308","id":221244071,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIxMjQ0MDcx","html_url":"https://github.com/dotnet/coreclr/pull/20308","diff_url":"https://github.com/dotnet/coreclr/pull/20308.diff","patch_url":"https://github.com/dotnet/coreclr/pull/20308.patch","issue_url":"https://api.github.com/repos/dotnet/coreclr/issues/20308","number":20308,"state":"open","locked":false,"title":"Fast-path ExecutionContext for ThreadPool items","user":{"login":"benaadams","id":1142958,"node_id":"MDQ6VXNlcjExNDI5NTg=","avatar_url":"https://avatars1.githubusercontent.com/u/1142958?v=4","gravatar_id":"","url":"https://api.github.com/users/benaadams","html_url":"https://github.com/benaadams","followers_url":"https://api.github.com/users/benaadams/followers","following_url":"https://api.github.com/users/benaadams/following{/other_user}","gists_url":"https://api.github.com/users/benaadams/gists{/gist_id}","starred_url":"https://api.github.com/users/benaadams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benaadams/subscriptions","organizations_url":"https://api.github.com/users/benaadams/orgs","repos_url":"https://api.github.com/users/benaadams/repos","events_url":"https://api.github.com/users/benaadams/events{/privacy}","received_events_url":"https://api.github.com/users/benaadams/received_events","type":"User","site_admin":false},"body":"`ExecutionContext.Run` has logic for saving and restoring the current contexts and extra logic to optimise the enregistering around exception handling.\r\n\r\nWhen items are run on the ThreadPool we can fast-path for the threads starting on the Default context and avoid stashing the current context to restore later (as it is Default). \r\n\r\nFor CallbackDefaultContext items we can further fast-path by not restoring the new context (as it is still the Default) and only need to return back to the Default context after the callback is run (in case it moves off the Defaults in the callback).\r\n\r\nAdditionally; if a naked exception is thrown on the ThreadPool it will crash the process; so the additional exception handling logic can be avoided.\r\n\r\nThe `ThreadPool.Dispatch` loop resets `ExecutionContext` and `SynchronizationContext` after the workitems to move the ThreadPool thread back onto the Default context from any `AsyncLocal<T>` leakage from Unsafe work items, CustomWorkItems or AsyncLocals being set in AsyncLocals `OnValuesChanged` handler to guarantee the ThreadPool threads are on the Default contexts when a workitem starts. * \r\n\r\nIn addition to the standard `ExecutionContext.RunInternal` (328 bytes asm) this introduces 3 fast-path overloads for running via `ExecutionContext` from the ThreadPool using the above preconditions.\r\n\r\n`ExecutionContext:RunFromThreadPoolDispatchLoop` (230 bytes asm), for \r\n`Task`/`AsyncStateMachineBox`/`AwaitTaskContinuation`/`Timer` using the `Task.ExecuteFromThreadPool` overload; where any exception must be captured and propagated after the Default context has been restored.\r\n\r\n`ExecutionContext:RunForThreadPoolUserWorkItem` (108 bytes asm), for QueueUserWorkItems that aren't on the default context.\r\n\r\n`ExecutionContext:RunForThreadPoolUserWorkItemWithDefaultContext` (71 bytes asm), for QueueUserWorkItems that are on the default context.\r\n\r\nAlso drops an additional delegate invocation for work items queued using the  `QueueUserWorkItem<TState>(Action<TState>, TState, Boolean)` overload by accepting the `Action<TState>` directly rather than requiring a wrapper to convert it to a `ContextCallback` delegate.\r\n\r\nResolves:  dotnet/corefx#32695\r\n\r\n*In `Dispatch` the currentThread is stored and used from the same lookup as the work queue to avoid calling `Thread.CurrentThread`  VM call https://github.com/dotnet/coreclr/pull/20308#issuecomment-435769584; and added some tweaks to the loop to enregister the locals https://github.com/dotnet/coreclr/pull/20308/commits/5db2e9f94ac3d32f1aad9957486b7893dc426bb8 to make up the difference.\r\n\r\n/cc @stephentoub @kouvel ","created_at":"2018-10-08T21:09:47Z","updated_at":"2018-11-07T20:20:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0bb1f875b1f717b37ed8533fa35d88722c041bb9","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/coreclr/pulls/20308/commits","review_comments_url":"https://api.github.com/repos/dotnet/coreclr/pulls/20308/comments","review_comment_url":"https://api.github.com/repos/dotnet/coreclr/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/20308/comments","statuses_url":"https://api.github.com/repos/dotnet/coreclr/statuses/a6aa3e22cc20acbac20b8b11ff78a7d3fa405ea6","head":{"label":"benaadams:threadpool-ec","ref":"threadpool-ec","sha":"a6aa3e22cc20acbac20b8b11ff78a7d3fa405ea6","user":{"login":"benaadams","id":1142958,"node_id":"MDQ6VXNlcjExNDI5NTg=","avatar_url":"https://avatars1.githubusercontent.com/u/1142958?v=4","gravatar_id":"","url":"https://api.github.com/users/benaadams","html_url":"https://github.com/benaadams","followers_url":"https://api.github.com/users/benaadams/followers","following_url":"https://api.github.com/users/benaadams/following{/other_user}","gists_url":"https://api.github.com/users/benaadams/gists{/gist_id}","starred_url":"https://api.github.com/users/benaadams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benaadams/subscriptions","organizations_url":"https://api.github.com/users/benaadams/orgs","repos_url":"https://api.github.com/users/benaadams/repos","events_url":"https://api.github.com/users/benaadams/events{/privacy}","received_events_url":"https://api.github.com/users/benaadams/received_events","type":"User","site_admin":false},"repo":{"id":30264189,"node_id":"MDEwOlJlcG9zaXRvcnkzMDI2NDE4OQ==","name":"coreclr","full_name":"benaadams/coreclr","private":false,"owner":{"login":"benaadams","id":1142958,"node_id":"MDQ6VXNlcjExNDI5NTg=","avatar_url":"https://avatars1.githubusercontent.com/u/1142958?v=4","gravatar_id":"","url":"https://api.github.com/users/benaadams","html_url":"https://github.com/benaadams","followers_url":"https://api.github.com/users/benaadams/followers","following_url":"https://api.github.com/users/benaadams/following{/other_user}","gists_url":"https://api.github.com/users/benaadams/gists{/gist_id}","starred_url":"https://api.github.com/users/benaadams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benaadams/subscriptions","organizations_url":"https://api.github.com/users/benaadams/orgs","repos_url":"https://api.github.com/users/benaadams/repos","events_url":"https://api.github.com/users/benaadams/events{/privacy}","received_events_url":"https://api.github.com/users/benaadams/received_events","type":"User","site_admin":false},"html_url":"https://github.com/benaadams/coreclr","description":"This repo contains the .NET Core runtime, called CoreCLR. It is an execution engine for .NET apps, performing functions such as IL byte code loading, compilation to machine code and garbage collection. The repo contains the complete up-to-date CoreCLR codebase.","fork":true,"url":"https://api.github.com/repos/benaadams/coreclr","forks_url":"https://api.github.com/repos/benaadams/coreclr/forks","keys_url":"https://api.github.com/repos/benaadams/coreclr/keys{/key_id}","collaborators_url":"https://api.github.com/repos/benaadams/coreclr/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/benaadams/coreclr/teams","hooks_url":"https://api.github.com/repos/benaadams/coreclr/hooks","issue_events_url":"https://api.github.com/repos/benaadams/coreclr/issues/events{/number}","events_url":"https://api.github.com/repos/benaadams/coreclr/events","assignees_url":"https://api.github.com/repos/benaadams/coreclr/assignees{/user}","branches_url":"https://api.github.com/repos/benaadams/coreclr/branches{/branch}","tags_url":"https://api.github.com/repos/benaadams/coreclr/tags","blobs_url":"https://api.github.com/repos/benaadams/coreclr/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/benaadams/coreclr/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/benaadams/coreclr/git/refs{/sha}","trees_url":"https://api.github.com/repos/benaadams/coreclr/git/trees{/sha}","statuses_url":"https://api.github.com/repos/benaadams/coreclr/statuses/{sha}","languages_url":"https://api.github.com/repos/benaadams/coreclr/languages","stargazers_url":"https://api.github.com/repos/benaadams/coreclr/stargazers","contributors_url":"https://api.github.com/repos/benaadams/coreclr/contributors","subscribers_url":"https://api.github.com/repos/benaadams/coreclr/subscribers","subscription_url":"https://api.github.com/repos/benaadams/coreclr/subscription","commits_url":"https://api.github.com/repos/benaadams/coreclr/commits{/sha}","git_commits_url":"https://api.github.com/repos/benaadams/coreclr/git/commits{/sha}","comments_url":"https://api.github.com/repos/benaadams/coreclr/comments{/number}","issue_comment_url":"https://api.github.com/repos/benaadams/coreclr/issues/comments{/number}","contents_url":"https://api.github.com/repos/benaadams/coreclr/contents/{+path}","compare_url":"https://api.github.com/repos/benaadams/coreclr/compare/{base}...{head}","merges_url":"https://api.github.com/repos/benaadams/coreclr/merges","archive_url":"https://api.github.com/repos/benaadams/coreclr/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/benaadams/coreclr/downloads","issues_url":"https://api.github.com/repos/benaadams/coreclr/issues{/number}","pulls_url":"https://api.github.com/repos/benaadams/coreclr/pulls{/number}","milestones_url":"https://api.github.com/repos/benaadams/coreclr/milestones{/number}","notifications_url":"https://api.github.com/repos/benaadams/coreclr/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/benaadams/coreclr/labels{/name}","releases_url":"https://api.github.com/repos/benaadams/coreclr/releases{/id}","deployments_url":"https://api.github.com/repos/benaadams/coreclr/deployments","created_at":"2015-02-03T20:56:42Z","updated_at":"2018-11-03T00:39:56Z","pushed_at":"2018-11-07T19:20:21Z","git_url":"git://github.com/benaadams/coreclr.git","ssh_url":"git@github.com:benaadams/coreclr.git","clone_url":"https://github.com/benaadams/coreclr.git","svn_url":"https://github.com/benaadams/coreclr","homepage":"","size":247989,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"b1b424f741af16a5df052ef11609c65d99686435","user":{"login":"dotnet","id":9141961,"node_id":"MDEyOk9yZ2FuaXphdGlvbjkxNDE5NjE=","avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":30092893,"node_id":"MDEwOlJlcG9zaXRvcnkzMDA5Mjg5Mw==","name":"coreclr","full_name":"dotnet/coreclr","private":false,"owner":{"login":"dotnet","id":9141961,"node_id":"MDEyOk9yZ2FuaXphdGlvbjkxNDE5NjE=","avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/dotnet/coreclr","description":"This repo contains the .NET Core runtime, called CoreCLR, and the base library, called System.Private.Corelib (or mscorlib). It includes the garbage collector, JIT compiler, base .NET data types and many low-level classes. We welcome contributions.","fork":false,"url":"https://api.github.com/repos/dotnet/coreclr","forks_url":"https://api.github.com/repos/dotnet/coreclr/forks","keys_url":"https://api.github.com/repos/dotnet/coreclr/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/coreclr/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/coreclr/teams","hooks_url":"https://api.github.com/repos/dotnet/coreclr/hooks","issue_events_url":"https://api.github.com/repos/dotnet/coreclr/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/coreclr/events","assignees_url":"https://api.github.com/repos/dotnet/coreclr/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/coreclr/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/coreclr/tags","blobs_url":"https://api.github.com/repos/dotnet/coreclr/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/coreclr/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/coreclr/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/coreclr/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/coreclr/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/coreclr/languages","stargazers_url":"https://api.github.com/repos/dotnet/coreclr/stargazers","contributors_url":"https://api.github.com/repos/dotnet/coreclr/contributors","subscribers_url":"https://api.github.com/repos/dotnet/coreclr/subscribers","subscription_url":"https://api.github.com/repos/dotnet/coreclr/subscription","commits_url":"https://api.github.com/repos/dotnet/coreclr/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/coreclr/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/coreclr/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/coreclr/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/coreclr/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/coreclr/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/coreclr/merges","archive_url":"https://api.github.com/repos/dotnet/coreclr/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/coreclr/downloads","issues_url":"https://api.github.com/repos/dotnet/coreclr/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/coreclr/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/coreclr/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/coreclr/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/coreclr/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/coreclr/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/coreclr/deployments","created_at":"2015-01-30T22:10:02Z","updated_at":"2018-11-07T20:14:23Z","pushed_at":"2018-11-07T20:14:01Z","git_url":"git://github.com/dotnet/coreclr.git","ssh_url":"git@github.com:dotnet/coreclr.git","clone_url":"https://github.com/dotnet/coreclr.git","svn_url":"https://github.com/dotnet/coreclr","homepage":"https://github.com/dotnet/core","size":252293,"stargazers_count":10480,"watchers_count":10480,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2503,"mirror_url":null,"archived":false,"open_issues_count":2013,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":2503,"open_issues":2013,"watchers":10480,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/coreclr/pulls/20308"},"html":{"href":"https://github.com/dotnet/coreclr/pull/20308"},"issue":{"href":"https://api.github.com/repos/dotnet/coreclr/issues/20308"},"comments":{"href":"https://api.github.com/repos/dotnet/coreclr/issues/20308/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/coreclr/pulls/20308/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/coreclr/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/coreclr/pulls/20308/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/coreclr/statuses/a6aa3e22cc20acbac20b8b11ff78a7d3fa405ea6"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"kouvel"}}