> Markdown version of [/videos/394-turbocharged-writing-high-performance-c-and-net-code](https://www.wearedevelopers.com/videos/394-turbocharged-writing-high-performance-c-and-net-code). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # Turbocharged: Writing High-Performance C# and .NET Code Steve Gordon proves that optimizing C# hot paths directly slashes your cloud costs. Master Span<T>, pipelines, and rigorous benchmarking to eliminate expensive garbage collection overhead. - **Speakers:** Steve Gordon - **Event:** World Congress 2022 - **Published:** June 15, 2022 - **Duration:** 39:56 - **URL:** https://www.wearedevelopers.com/videos/394-turbocharged-writing-high-performance-c-and-net-code ## Summary In this developer-focused session, Steve Gordon explores practical techniques for writing high-performance C# and .NET applications. The core narrative centers around a rigorous optimization cycle: measuring execution time, throughput, and memory allocations, followed by targeted improvements to reduce garbage collection overhead. Using hands-on examples, the presentation demonstrates how to identify performance bottlenecks mathematically through micro-benchmarking with BenchmarkDotNet, stressing the importance of profiling production environments against real workloads before making assumptions. Gordon introduces several powerful .NET types designed to minimize heap allocations and speed up processing. Key among these are `Span<T>` and `ReadOnlySpan<T>`, memory-safe structs that allow slice operations over contiguous regions of arrays and strings without allocating new memory. He addresses async and lifecycle limitations by pairing spans with `Memory<T>`, and covers pooling temporary buffers via `ArrayPool<T>` to avoid short-lived object allocations that put immense pressure on the garbage collector. Additionally, `System.IO.Pipelines` is showcased as a high-performance alternative to traditional generic streaming, dramatically reducing memory overhead when parsing large datasets off the wire or disk. The session emphasizes that optimization should not be a ubiquitous goal, but rather a deliberate business decision applied strictly to hot paths. Developers are advised to translate performance gains into concrete monetary value—such as mapping reduced memory footprints and faster throughputs into minimizing the number of cloud microservice instances required. By focusing entirely on measurable, incremental changes, engineering teams can deliver substantial bottom-line return on investment while maintaining clean, efficient server-side C# codebases. **Keywords:** c# performance optimization, .net memory management, benchmarkdotnet micro-benchmarking, garbage collection overhead, heap allocation reduction, span memory slicing, readonlyspan string parsing, memory struct async handling, arraypool buffer reuse, system.io.pipelines stream processing, hot path profiling, valuetask vs task, stack vs heap allocation, microservice computing costs, production metrics monitoring ## Chapters 1. **Core metrics for assessing code performance** (00:12) — Execution time, throughput, and memory allocations serve as the primary metrics for application performance. 1. **The fundamental cycle for code optimization** (02:34) — Accurately measuring and incrementally optimizing code prevents developers from making incorrect performance assumptions. 1. **Profiling tools and production data gathering** (03:56) — Diagnostic tools and production metrics reveal actual resource consumption to establish a baseline. 1. **Executing precision micro benchmarks with BenchmarkDotNet** (05:59) — Micro-benchmarking frameworks prevent statistical noise by validating execution performance over thousands of continuous iterations. 1. **Utilizing continuous memory views with span** (08:24) — Treating arrays as consistent continuous references circumvents the constraints surrounding direct memory allocation limits. 1. **Comparing slicing and array copying benchmarks** (11:04) — Slicing into pre-existing memory locations enables constant-time subset access without spawning duplicate objects. 1. **Overcoming the stack constraints with memory abstractions** (16:41) — Substituting spans with memory references enables the usage of asynchronous methods while preserving safety rules. 1. **Optimizing text parsing without surplus string allocations** (19:28) — Leveraging temporary stack buffers eliminates unnecessary garbage collection iterations during high-volume message ingestion. 1. **Reusing temporary buffers alongside the array pool** (23:41) — Renting standardized arrays across operations reduces heap churn associated with recurrent short-term variables. 1. **Amortizing input latency with pipeline data abstractions** (25:49) — Replacing conventional streams with standardized pipeline readers accelerates handling asynchronous data ingress operations. 1. **Transitioning stream processing to continuous pipeline workflows** (27:21) — Advancing the internal buffer position concurrently with decompression parsing reduces excessive memory utilization during concurrent executions. 1. **Justifying high performance optimizations to business leaders** (30:55) — Translating capability improvements into concrete structural hardware savings empowers leaders to endorse systemic codebase refactorings. 1. **Strategies for arrays and the value task struct** (36:05) — Adopting value tasks within mixed asynchronous scenarios mitigates the overhead of returning standard synchronous generic allocations. ## Related Moments - [Introduction to systems programming and performance in .NET](https://www.wearedevelopers.com/videos/100138-is-it-still-c-practical-systems-programming-with-net-war-stories-included) (from "Is it still C#? Practical systems programming with .NET (war stories included)") - [Discussion on JIT memory parameters and cross-language benchmarking](https://www.wearedevelopers.com/videos/240-just-in-time-compilation-in-jvm) (from "Just-in-time Compilation in JVM") - [Debugging performance bottlenecks with developer tools](https://www.wearedevelopers.com/videos/817-the-illusion-of-a-performant-web-application) (from "The Illusion of a Performant Web Application") - [Reviewing optimization improvements in Lighthouse](https://www.wearedevelopers.com/videos/453-is-your-progressive-web-app-lazy-how-to-read-and-improve-your-pwa-performance) (from "Is your Progressive Web App Lazy? How to read and improve your PWA Performance") - [Final performance results and key architectural takeaways](https://www.wearedevelopers.com/videos/733-accelerating-authentication-architecture-taking-passwordless-to-the-next-level) (from "Accelerating Authentication Architecture: Taking Passwordless to the Next Level") - [Prioritizing application startup efficiency over systemic throughput metrics](https://www.wearedevelopers.com/videos/104-cloud-chaos-and-microservices-mayhem) (from "Cloud Chaos and Microservices Mayhem") ## Related Articles - [Get Old, go Slow, Write Code!](https://www.wearedevelopers.com/magazine/81-get-old-go-slow-write-code) - [Dev Digest 139 - Soft and hard queries](https://www.wearedevelopers.com/magazine/487-dev-digest-139-soft-and-hard-queries) - [Liuba Gonta and Yuliya Khadasevic - GitHub Copilot Beyond the Basics - 10 Ways to Elevate Your Coding](https://www.wearedevelopers.com/magazine/490-liuba-gonta-and-yuliya-khadasevic-github-copilot-beyond-the-basics-10-ways-to-elevate-your-coding) - [MLops – Deploying, Maintaining And Evolving Machine Learning Models in Production](https://www.wearedevelopers.com/magazine/115-mlops-deploying-maintaining-and-evolving-machine-learning-models-in-production) ## Related Jobs - [Senior Software Engineer,Billing](https://www.wearedevelopers.com/jobs/ext/1991843-senior-software-engineer-billing) at **GitHub** - [Senior Software Engineer, Enterprise Products](https://www.wearedevelopers.com/jobs/ext/1841248-senior-software-engineer-enterprise-products) at **GitHub** - [Senior Software Engineer](https://www.wearedevelopers.com/jobs/ext/15942-senior-software-engineer) at **GitHub** - [Principal Software Engineer, Database Infrastructure](https://www.wearedevelopers.com/jobs/ext/1465908-principal-software-engineer-database-infrastructure) at **GitHub** - [Senior Software Engineer, Client Apps Platform](https://www.wearedevelopers.com/jobs/ext/1773893-senior-software-engineer-client-apps-platform) at **GitHub** - [Principal Software Engineer, Enterprise AI Platform](https://www.wearedevelopers.com/jobs/ext/1467292-principal-software-engineer-enterprise-ai-platform) at **GitHub**