Skip to content

perf: collapse 4-layer async forwarding chain in test execution #5714

@thomhurst

Description

@thomhurst

Summary

The per-test entry point chains through 4 async layers before any real work happens, each materializing its own state machine. Estimated 2 state machines per test removed.

Evidence

Trace (inclusive %):

11.54% TestRunner.ExecuteTestAsync
11.28% TestRunner.ExecuteTestInternalAsync
11.10% TestCoordinator.ExecuteTestAsync           ← pure forward
11.10% TestCoordinator.ExecuteTestInternalAsync
10.13% TestCoordinator.ExecuteTestLifecycleAsync
 9.94% TestExecutor.ExecuteAsync

TUnit.Engine/Services/TestExecution/TestCoordinator.cs:50-51 is a pure forwarding async method:

public ValueTask ExecuteTestAsync(AbstractExecutableTest test, CancellationToken cancellationToken)
    => ExecuteTestInternalAsync(test, cancellationToken);

ExecuteTestLifecycleAsync is an inline-able wrapper on the no-retry branch.

Proposed fix

  • Inline pure-forward TestCoordinator.ExecuteTestAsync into its caller.
  • Inline ExecuteTestLifecycleAsync into ExecuteTestInternalAsync for the no-retry path.
  • Audit TestRunner.ExecuteTestAsyncExecuteTestInternalAsync for the same pattern.

Expected impact

  • 2-3 async state machines per test removed.
  • Directly reduces AsyncMethodBuilderCore.Start 2.93% self time observed in the trace.

Files

  • TUnit.Engine/Services/TestExecution/TestCoordinator.cs:50-51, 53, 279
  • TUnit.Engine/Scheduling/TestRunner.cs:48, 91, 125
  • TUnit.Engine/TestExecutor.cs:69

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .net codeenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions