Performance considerations
Talking about the overhead, while functional programming techniques such as composition and pipelines offer improved readability and maintainability, it’s important to understand their performance implications. When we compose functions, the compiler generates a series of nested method calls. This can lead to multiple stack frame allocations, impacting performance for deeply nested compositions.
To better understand the difference, let’s benchmark different approaches:
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running; [MemoryDiagnoser] public class FunctionalPerformance { private IEnumerable<int> _numbers; [GlobalSetup] public void Setup() { _numbers = Enumerable.Range(0, 1_000_000_000); } [Benchmark] ...