ASP.NET Core Performance

← Tutorials Home

Introduction

ASP.NET Core is built for high performance. This tutorial covers techniques, tools, and best practices to help you write faster, more scalable applications.

Key Performance Areas

Sample Code: Optimizing a Controller

using Microsoft.AspNetCore.Mvc;

[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
    private static readonly WeatherForecast[] _forecasts = GenerateForecasts();

    [HttpGet]
    public IEnumerable<WeatherForecast> Get()
    {
        // No async/await overhead for CPU‑bound work
        return _forecasts;
    }

    private static WeatherForecast[] GenerateForecasts()
    {
        var rng = new Random();
        return Enumerable.Range(1, 5).Select(index => new WeatherForecast
        {
            Date = DateTime.Now.AddDays(index),
            TemperatureC = rng.Next(-20, 55),
            Summary = Summaries[rng.Next(Summaries.Length)]
        }).ToArray();
    }

    private static readonly string[] Summaries = new[]
    {
        "Freezing", "Bracing", "Chilly", "Cool", "Mild",
        "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
    };
}

Interactive Throughput Calculator

Estimated CPU cores needed: 2

Further Reading