From Jason Turner
Watch on YouTube

Summary

This episode examines the performance impact of using lambdas in C++. Jason demonstrates that while lambdas generate additional assembly code in unoptimized builds, this overhead completely disappears with even minimal optimization levels. Through comparative analysis using Compiler Explorer, he shows that lambdas compile to essentially the same code as manually implemented function objects, and with optimizations enabled, they're as efficient as direct code. The key insight is that lambdas are truly zero-cost abstractions in optimized builds, but developers using debug builds should consider using -Og or at least -O1 to eliminate unnecessary overhead.

Resources

Tags