Leanpub Header

Skip to main content

High-Performance .NET: From JIT to Hardware

A Systems-Level Guide to Writing Fast .NET Applications

High-Performance .NET: From JIT to Hardware
This book is 100% completeLast updated on 2026-09-16

Go beyond writing code that works. Learn what really happens inside .NET, from C# and the JIT to memory, CPU execution and the operating system. This practical guide shows experienced developers how to measure performance, find real bottlenecks and make targeted improvements that hold up in production.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
214
Pages
About

About

About the Book

This book teaches experienced .NET developers how to understand, measure, diagnose, and systematically improve the performance of modern .NET applications from source code down to the CPU and operating system. You will learn how the .NET runtime executes your code, how the JIT compiler translates C# into machine instructions, how the garbage collector manages memory, how modern CPUs execute those instructions, and how to use professional tooling to find and fix real bottlenecks. The book is built around .NET 8 LTS and C# 12, with version-specific behavior clearly identified where it matters.

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. Throughout his career, he has designed, secured, analyzed and tested complex software and infrastructure, with a particular focus on understanding how systems fail and how they can be made more secure.

Outside of work, Steve enjoys sharing knowledge with the technology community. He collaborates with researchers, industry experts and technology professionals to write practical books covering software development, cybersecurity, cloud computing, networking, DevOps, artificial intelligence and enterprise technologies. His books focus on practical learning through clear explanations, real-world examples and hands-on exercises. With more than two decades of industry experience, his goal is to help IT professionals, students and technology enthusiasts build useful skills and stay current in a rapidly changing industry.

We believe readers deserve to know how our books are created. Most of our authors are not native English speakers, so we use AI to help translate, proofread manuscripts, fix grammar, improve sentence structure and make technical explanations easier to read. AI is used as an editing tool only. It does not replace the research, technical knowledge or hands-on experience behind our books. Some of our authors also prefer to remain anonymous for privacy or professional reasons. In those cases, we publish their work under a different name. The author's name may be different, but the quality of the content and our review process remain the same.

Every book is written, reviewed and maintained by experienced technology professionals, with contributions from our private technical community of more than 420 engineers and researchers. We spend far more time validating technical accuracy and keeping our content up to date than generating text. We are always interested in working with experienced professionals who have deep expertise in a particular technology or domain. If you would like to publish a book with us or help review an existing manuscript, we'd love to hear from you. Send us a message describing your area of expertise. We are especially interested in niche technologies, specialized skills and emerging topics that are underrepresented in existing technical literature.

If you look through the contents of our books, you'll see practical examples, detailed explanations and material that is regularly updated. Our goal is to publish books that professionals can actually rely on, not low-effort AI-generated content. If you ever feel that one of our books does not meet that standard, Leanpub offers a 60-day money-back guarantee. Feel free to request a refund if you are not satisfied with your purchase.

Contents

Table of Contents

A Systems-Level Guide to Writing Fast .NET Applications

Introduction

Chapter 1: Why Performance Matters and How to Think About It

  1. The Hidden Costs of Slow Software
  2. Throughput Versus Latency: What Are You Optimizing?
  3. The Performance Stack: From C# to Silicon
  4. Evidence-Based Optimization: The Scientific Method Applied
  5. Common Mistakes and False Intuitions

Chapter 2: The .NET Runtime Architecture

  1. Inside the Execution Engine: CorRuntime and CoreCLR
  2. The Type System: Types, Metadata, and Runtime Representation
  3. Assembly Loading and Isolation: AssemblyLoadContext and Performance
  4. The Execution Pipeline: From Source to Machine Code
  5. Understanding Runtime Overhead: What the CLR Actually Does

Chapter 3: JIT Compilation and Code Generation

  1. The RyuJIT Compiler: Architecture and Optimization Pipeline
  2. On-Demand Compilation: When Methods Get Compiled
  3. Optimization Passes: From IL to Optimized Machine Code
  4. Reading Disassembly: Understanding What the JIT Produced
  5. How Your C# Constructs Translate to Machine Code

Chapter 4: Tiered Compilation and Dynamic Optimization

  1. ReadyToRun and Precompilation: Reducing JIT Overhead
  2. Tiered Compilation: JIT Tiering for Startup and Steady-State
  3. Crossgen2 and Full AOT Compilation
  4. Profile-Guided Optimization: Using Runtime Data to Improve Code
  5. Choosing Compilation Modes for Different Scenarios

Chapter 5: Native AOT

  1. How Native AOT Works: The Compilation Story
  2. Startup Performance and Memory Footprint Gains
  3. Feature Limitations: What Native AOT Cannot Do
  4. Trim Mode and Dependency Analysis
  5. When to Use Native AOT: Real-World Tradeoffs

Chapter 6: Method Inlining and Devirtualization

  1. Method Inlining: How It Works and Why It Matters
  2. Inlining Decisions: Size Limits, Heuristics, and Exceptions
  3. Devirtualization: Turning Virtual Calls into Direct Calls
  4. When Inlining and Devirtualization Fail
  5. Designing Code the JIT Can Optimize Aggressively

Chapter 7: Value Types, Reference Types, and Struct Design

  1. Stack Versus Heap: Understanding Where Types Live
  2. Value Type Semantics: Copies, Moves, and Escape Analysis
  3. Struct Design: When Structs Help and When They Hurt
  4. Boxing and Unboxing: The Hidden Performance Cost
  5. Escaping and In-Struct Storage of Value Types

Chapter 8: Object Layout, Memory, and Allocation

  1. Object Headers and Layout: Understanding Managed Object Structure
  2. Allocation: The Allocator and the Thread-Local Allocation Buffer
  3. Padding, Alignment, and Memory Wastage
  4. Designing Memory-Efficient Types
  5. Field Ordering and Cache-Friendly Layout

Chapter 9: Boxing, Generics, and Reflection

  1. Boxing and Unboxing: Detailed Mechanics and Alternatives
  2. Generic Code Generation: Code Sharing Across Types
  3. Generic Virtual Calls and Interface Constraints
  4. Reflection Performance: Costs and Patterns
  5. Source Generation and Compiled Reflection as Alternatives

Chapter 10: Spans, Memory, and Zero-Allocation Patterns

  1. Span and Memory: The Abstraction Story
  2. How Spans Work: Pointers, Handles, and Safety
  3. Stackalloc and Native Arrays
  4. Zero-Allocation Parsing and Processing Patterns
  5. When Zero-Allocation Does Not Help

Chapter 11: Object Pooling and ArrayPool

  1. Why Object Pooling Works: Avoiding GC Pressure
  2. ArrayPool: Built-In Array Reuse
  3. Building Custom Object Pools
  4. Concurrency and Pooling: Thread Safety Considerations
  5. When Pooling Makes Things Worse

Chapter 12: Collections and Data Structures Performance

  1. List and Array: Allocation Patterns and Growth
  2. Dictionary Performance: Hashing, Collisions, and Load Factors
  3. Concurrent Collections: Overhead and Alternatives
  4. LINQ and Allocation-Free Query Patterns
  5. Choosing the Right Structure for Your Access Pattern

Chapter 13: The Garbage Collector: Generations and Algorithms

  1. How Generational GC Works: The Theory and Practice
  2. The Nursery: Short-Lived Object Collection
  3. Promotion: How Objects Survive and Age
  4. Old Generation Collection: Compacting Long-Lived Objects
  5. Tracing Algorithms and Concurrent Marking

Chapter 14: GC Modes: Workstation, Server, Background, and Latency

  1. Workstation GC Versus Server GC: Fundamental Differences
  2. Background GC: Reducing Stop-the-World Pauses
  3. Low-Latency and High-Throughput Modes
  4. Large Object Heap: Behavior and Pitfalls
  5. Pinned Object Heap and Pinning Costs

Chapter 15: Finalization, IDisposable, and Cleanup

  1. The Finalization Queue: How Finalizers Work
  2. Why Finalizers Are Expensive
  3. The Dispose Pattern: Managed and Unmanaged Resources
  4. SuppressFinalize and When to Use It
  5. Alternatives to Finalization

Chapter 16: GC Tuning, Diagnostics, and Troubleshooting

  1. GC Configuration Options and Environment Variables
  2. Reading GC Counters and Metrics
  3. Diagnosing Excessive Allocations
  4. LOH Fragmentation: Detection and Remediation
  5. Tuning GC for Different Workloads

Chapter 17: Async State Machines, Tasks, and ValueTask

  1. How async and await Work: The Generated State Machine
  2. Task Allocation and Lifecycle
  3. ValueTask: Benefits and Pitfalls
  4. Async Overhead: Measuring and Reducing It
  5. Async Patterns for High-Performance Scenarios

Chapter 18: Delegates, Closures, and Event Performance

  1. Delegates: How They Work Under the Hood
  2. Closures and Captured Variables: The Hidden Allocation
  3. Multicast Delegates and Event Invocation Performance
  4. Avoiding Closure Allocations in Hot Paths
  5. Delegate Performance Patterns

Chapter 19: Thread Pools, Synchronization, and Concurrency

  1. The Thread Pool: Architecture and Behavior
  2. Lock Types: Monitor, Mutex, Semaphore, and SpinLock
  3. Lock Contention: Detection and Mitigation
  4. Reader-Writer Locks and Partitioning Strategies
  5. High-Level Concurrency Patterns in .NET

Chapter 20: Lock-Free Programming and Memory Ordering

  1. Interlocked Operations: Atomic Updates
  2. Memory Ordering and the Memory Barrier
  3. Volatile Semantics in C# and .NET
  4. Building Lock-Free Data Structures
  5. When Lock-Free Is Not Actually Faster

Chapter 21: I/O, Networking, and Serialization Performance

  1. Synchronous Versus Asynchronous I/O: Mechanisms and Performance
  2. Socket and Networking Performance
  3. Span-Based I/O and Zero-Copy Patterns
  4. Serialization Formats: Performance Comparison
  5. Binary Serialization and Protocol Buffers

Chapter 22: SIMD, Vectorization, and Hardware Intrinsics

  1. SIMD Architecture: Single Instruction Multiple Data
  2. System.Numerics.Vectors and Portable SIMD
  3. Hardware Intrinsics: Direct CPU Instruction Access
  4. AutoSIMD and Compiler Vectorization
  5. Practical SIMD in .NET: Real Performance Gains

Chapter 23: CPU Architecture, Caches, and Branch Prediction

  1. CPU Execution Pipelines: How Instructions Really Run
  2. Branch Prediction: Cost of Wrong Predictions
  3. CPU Caches: L1, L2, L3, and Cache Lines
  4. Cache Locality and Data Layout
  5. False Sharing and Cache Line Contention

Chapter 24: Memory Subsystem, NUMA, and Hardware Considerations

  1. The Memory Hierarchy: From Registers to Main Memory
  2. Memory Bandwidth: When It Becomes the Bottleneck
  3. NUMA: Non-Uniform Memory Access and Awareness
  4. x64 Versus ARM64: Architectural Differences
  5. Modern Hardware Effects on .NET Performance

Chapter 25: Benchmarking: Methodology and Tools

  1. The Scientific Method for Performance Work
  2. BenchmarkDotNet: Architecture and Features
  3. Controlling Variables and Isolation
  4. Statistical Significance and Noise
  5. Common Benchmarking Mistakes

Chapter 26: Profiling, Tracing, and Diagnostics

  1. Profiling Approaches: Sampling Versus Instrumentation
  2. EventPipe and ETW: The Tracing Infrastructure
  3. PerfView: Deep Runtime Analysis
  4. dotnet-trace, dotnet-counters, dotnet-dump
  5. Production Profiling and Diagnostics

Chapter 27: Disassembly Analysis and Flame Graphs

  1. Reading JIT Disassembly Output
  2. Understanding Assembly: Registers, Instructions, and Calls
  3. Generating Flame Graphs from Profiling Data
  4. Interpreting Flame Graphs: Finding the Real Bottleneck
  5. Combining Disassembly and Flame Graphs for Analysis

Chapter 28: Production Observability and Performance Monitoring

  1. Runtime Counters for Production Monitoring
  2. Tracing in Production: Overhead and Safety
  3. Metrics and Alerting for Performance Degradation
  4. Correlating Application and Infrastructure Metrics
  5. Continuous Performance Regressions and Guardrails

Chapter 29: Case Studies and Real-World Performance Engineering

  1. Case Study: Optimizing a CPU-Bound Computational Workload
  2. Case Study: Reducing Allocations in a High-Throughput Service
  3. Case Study: Tuning for Low Latency in a Trading System
  4. Case Study: Optimizing Startup and Deployment with Native AOT
  5. Case Study: Concurrency Optimization in a Database-Backed API

Conclusion: The Performance Engineering Mindset

References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub