From a5ce57cc848324a9591792c32d1512222f83d51f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 6 Oct 2026 22:12:10 +0000 Subject: [PATCH 1/2] Default SynchronousAwaiter.Await to a blocking wait instead of a CPU-spinning busy-wait RecordStart/RecordResult (FrameworkHandlerAdapter) and test-case discovery (TestCaseDiscoverySinkAdapter) call Await() once per test/test-case, so this runs on every test in a VSTest-bridged run. The previous default (busyWait: true) spun on SpinWait.SpinOnce() in a tight loop until the awaited publish task completed, instead of blocking the thread. For the common case (an already-completed task, e.g. an unbounded channel write) this made no difference, but whenever the awaited publish routed to an inline IBlockingDataConsumer doing real synchronous work, spinning burned CPU cycles with no latency benefit over a kernel-level block. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Helpers/SynchronousAwaiter.cs | 8 +++++++- .../InternalAPI.Unshipped.txt | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Helpers/SynchronousAwaiter.cs b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Helpers/SynchronousAwaiter.cs index 8db016da73c..c19445d2ab4 100644 --- a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Helpers/SynchronousAwaiter.cs +++ b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Helpers/SynchronousAwaiter.cs @@ -8,7 +8,7 @@ namespace Microsoft.Testing.Extensions.VSTestBridge.Helpers; /// internal static class SynchronousAwaiter { - public static void Await(this Task valueTask, bool busyWait = true) + public static void Await(this Task valueTask, bool busyWait = false) { if (busyWait) { @@ -23,6 +23,12 @@ public static void Await(this Task valueTask, bool busyWait = true) } else { + // GetAwaiter().GetResult() blocks the calling thread the same way spinning does (both + // keep this thread from returning to the producer until the task completes), but it parks + // the thread on a kernel wait handle instead of burning CPU polling IsCompleted. Every call + // site here is invoked once per test start/end or per discovered test case, so for large + // suites the busy-wait default used to hold a core pegged for no measurable latency benefit + // whenever the awaited publish involved any real (even inline-blocking-consumer) work. valueTask.GetAwaiter().GetResult(); } } diff --git a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/InternalAPI.Unshipped.txt b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/InternalAPI.Unshipped.txt index 7dc5c58110b..25b74a3b0e7 100644 --- a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/InternalAPI.Unshipped.txt +++ b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/InternalAPI.Unshipped.txt @@ -1 +1,3 @@ #nullable enable +*REMOVED*static Microsoft.Testing.Extensions.VSTestBridge.Helpers.SynchronousAwaiter.Await(this System.Threading.Tasks.Task! valueTask, bool busyWait = true) -> void +static Microsoft.Testing.Extensions.VSTestBridge.Helpers.SynchronousAwaiter.Await(this System.Threading.Tasks.Task! valueTask, bool busyWait = false) -> void From b99994e72491a164776c38cd0eaf955d9137c637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 7 Oct 2026 11:34:02 +0200 Subject: [PATCH 2/2] Refine comments on SynchronousAwaiter behavior Updated comments to clarify behavior of GetAwaiter().GetResult() and its impact on thread management. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../Helpers/SynchronousAwaiter.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Helpers/SynchronousAwaiter.cs b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Helpers/SynchronousAwaiter.cs index c19445d2ab4..7956aa82693 100644 --- a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Helpers/SynchronousAwaiter.cs +++ b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Helpers/SynchronousAwaiter.cs @@ -23,12 +23,9 @@ public static void Await(this Task valueTask, bool busyWait = false) } else { - // GetAwaiter().GetResult() blocks the calling thread the same way spinning does (both - // keep this thread from returning to the producer until the task completes), but it parks - // the thread on a kernel wait handle instead of burning CPU polling IsCompleted. Every call - // site here is invoked once per test start/end or per discovered test case, so for large - // suites the busy-wait default used to hold a core pegged for no measurable latency benefit - // whenever the awaited publish involved any real (even inline-blocking-consumer) work. + // Block rather than explicitly poll when the task is incomplete. + // Already-completed tasks, including uncontended synchronous inline consumption, + // do not wait; GetResult still propagates faults and cancellation. valueTask.GetAwaiter().GetResult(); } }