Lowering in C#: What's really going on in your code?
summary
Explains how C# lowering rewrites high‑level code into concrete mechanics: foreach becomes a scoped while that introduces two casts and calls getEnumerator called once, lambdas get tiny helper classes with closure hoisting of locals, and yield/async become state‑machine classes whose MoveNext drives execution. Shows concrete performance impacts (extra allocations, surprising lifetime retention), points to Roslyn source and SharpLab as tools to inspect generated code and verify whether the lowered code performs or allocates as expected.
AI-written summary · about
chapters (14)
- 0:00Intro
- 0:31What is lowering
- 3:51Linked queries
- 4:56Variables
- 7:17Performance
- 9:44Understanding how things work
- 10:05For each loop
- 20:15lambdas
- 25:30closing over
- 26:42yield
- 28:07helper
- 28:46numerator
- 29:55movenext
- 39:52SharpLab
related talks
01h 00mWhat were they thinking? Language design choices that seem wrong, until they don't.
30mLow Level JavaScript
41mWhat’s Next in C#
45mFreaking computers, how do they work?
17mDemystifying (JavaScript) engines
23mA sneak peek into super optimized code in JS frameworks
25mJavaScript engines how do they even?
26mJavaScript Level 9000
