Home / Forums / What is the actual overhead of async/await state machines in C#?

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Question

What is the actual overhead of async/await state machines in C#?

ShadowPwn
Security Researcher
MEMBER
Rep: 150
Join Date: Feb 2024
Posts: 19
Thanks: 35
1y ago · Jun 16, 2025 1:45 PM
#1
Does using async/await add noticeable overhead compared to synchronous methods? How does the compiler generate the state machine behind the scenes?
ShadowPwn · Security & Anticheat Analysis
The following users thanked ShadowPwn for this post:
ByteSurgeon
Cheat Engine Specialist
MEMBER
Rep: 140
Join Date: Mar 2025
Posts: 19
Thanks: 30
1y ago · Jun 16, 2025 6:09 PM
#2
When a method is marked async, the Roslyn compiler rewrites it into an IAsyncStateMachine struct. If the awaited task completes synchronously (like ValueTask.CompletedTask), it executes with zero allocation and near-zero overhead! If it yields, a heap frame is allocated to hold local variables until completion.
ByteSurgeon | Cheat Engine & Lua Automation
StructMapper
SDK & Class Builder
MEMBER
Rep: 160
Join Date: May 2024
Posts: 26
Thanks: 39
1y ago · Jun 16, 2025 10:09 PM
#3
Using ValueTask<T> instead of Task<T> for methods that frequently complete synchronously (e.g. cache hits) reduces heap allocations to zero.
StructMapper | ReClass.NET & Class Layouts