An N+1 query looks like a staircase
I've been building AspNetDebugDashboard on and off for a while. It's my take on Laravel Telescope for ASP.NET Core: you add one NuGet package, and in Development you get a page at /_debug with every request your app handled, the EF Core queries each one ran, outgoing HttpClient calls, logs and exceptions. The part that always bugged me was the request detail. You'd open a slow request and get…
An N+1 query in a programming context resembles a staircase. This comparison comes from the AspNetDebugDashboard, a tool that monitors and analyzes requests in ASP.NET Core applications. When debugging, developers often encounter long lists of queries and external calls that make it hard to understand the overall performance.
In version 2.5 of the AspNetDebugDashboard, the visual representation of these details changed from a list to a timeline. This makes it easier to identify slow requests and pinpoint the sources of performance issues. For instance, consider a report endpoint that loads 20 orders, loops through each order's items, and then calls a shipping-rates service. This results in 20 queries running one after another, each taking up space on the timeline.
The 20 queries are grouped together, forming a staircase-like pattern on the timeline. Meanwhile, the HTTP call to the shipping-rates service starts only after all the queries have finished. By adding a delay to the database commands, the sample demonstrates how a database located on a different network can affect the overall timing. Additionally, a "batched" feature reduces the number of queries from 21 to 1, bringing the request time down from 393 ms to just 6 ms.
However, it's important to note that the actual performance numbers will vary depending on the specific database being used. The AspNetDebugDashboard is designed for local development use and stores data in a local LiteDB file, turning on only in the Development environment unless specified otherwise. It works with .NET versions 8 through 11 and is intended for individual developers working on their machines.
For production environments, developers should still consider using a robust Application Performance Management (APM) solution.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.