Skip to content

.NET 11: async SqlClient queries use 20–35% more CPU than on .NET 10 (Windows, same SqlClient binary) #137300

Open

Description

@rushfrisby

Description

After moving an ASP.NET Core service from .NET 10 to .NET 11, each API request costs 4–24% more process CPU at the same
throughput and latency. Measuring the request path layer by layer put almost all of it in Microsoft.Data.SqlClient. The
ASP.NET Core pipeline itself got cheaper on .NET 11 (9–28% less CPU per request), and JWT validation costs the same.

The repro below has no other dependencies. It runs one query loop, built from the same source for net10.0 and
net11.0. Both builds load the same SqlClient assembly (7.1.1's net9.0 build), and the only thing that changes is
the runtime. Queries per second and bytes allocated per query are the same on both. Only CPU time per query goes up.

Reproduction Steps

Full project (csproj, Program.cs, run.ps1, README): https://github.com/rushfrisby/sqlclient-net11-repro

Each of N workers runs this in a closed loop:

await using var connection = new SqlConnection(connectionString);   // pooled
await connection.OpenAsync();
await using var command = new SqlCommand("SELECT Id, Name, Email, CreatedOn FROM dbo.Item WHERE Id = @Id", connection);
command.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int) { Value = rng.Next(100_000) });
await using var reader = await command.ExecuteReaderAsync();
while (await reader.ReadAsync()) { /* read the four columns */ }

After a 5 s warm-up it measures for 15 s: queries per second, Process.TotalProcessorTime divided by queries, and
GC.GetTotalAllocatedBytes divided by queries.

  1. docker run -d --name sqlclient-repro -e ACCEPT_EULA=Y -e "MSSQL_SA_PASSWORD=Repro-Passw0rd!" -p 14339:1433 mcr.microsoft.com/mssql/server:2022-latest
  2. dotnet run -c Release -f net11.0 -- --setup (creates a 100,000-row table)
  3. pwsh ./run.ps1, which builds both TFMs and runs them alternately. Each process is pinned to the same 8 logical CPUs
    (4 performance cores with hyperthreading) through an inherited affinity mask, so Environment.ProcessorCount is 8
    from startup on both. Options: -SqlClientVersion, -ManagedSni, -Mars.

Expected behavior

CPU time per query about the same on .NET 11 as on .NET 10.

Actual behavior

Process CPU µs per query, mean of alternating 15 s runs, with min–max in brackets:

SqlClient Networking Workers .NET 10.0.14 .NET 11.0.0 Change Runs
7.1.1 native SNI (default) 4 79.7 [75.8–86.7] 108.3 [97.1–121.5] +36% 3 + 3
7.1.1 native SNI (default) 16 67.6 [62.7–70.3] 82.8 [78.3–88.9] +22% 3 + 3
8.0.0-preview1.26313.4 native SNI 4 91.9 [86.8–97.0] 102.2 [91.4–112.9] +11% 2 + 2
8.0.0-preview1.26313.4 native SNI 16 68.8 [68.0–69.5] 84.8 [84.6–85.0] +23% 2 + 2
7.1.1 managed (UseManagedNetworkingOnWindows) 4 93.0 [86.9–99.1] 97.3 [94.5–100.0] +5% 2 + 2
7.1.1 managed (UseManagedNetworkingOnWindows) 16 73.5 [70.1–76.8] 91.1 [90.8–91.3] +24% 2 + 2

On both runtimes, throughput is about 20,500 queries/s at 16 workers and about 7,400 at 4, because the loop is bound
by the round trip. Allocations are 5,191 B per query on .NET 10 and 5,183 B on .NET 11 (native SNI); managed SNI is
5,890 vs 5,888 B.

At 16 workers, where the measurements are steadiest, the .NET 11 and .NET 10 ranges don't overlap in any configuration.

Regression?

Yes, compared with .NET 10.0.14, the only .NET 10 version I tested.

Known Workarounds

None found:

  • Managed SNI uses about the same or more CPU on both runtimes, and still regresses at 16 workers.
  • SqlClient 8.0.0-preview1 (the net10.0 build with the new native SNI) behaves like 7.1.1.
  • In the full service, turning off thread pool spinning on both runtimes (DOTNET_ThreadPool_UnfairSemaphoreSpinLimit=0)
    lowered CPU on both, but .NET 11 still cost 6–20% more per request. So the extra time isn't spin-waiting.

Configuration

  • .NET SDK 11.0.100 (runtime 11.0.0) and .NET SDK 10.0.403 (runtime 10.0.14), x64
  • Windows 11 Pro 10.0.26300, Intel Core i9-12900KF, 64 GB
  • Server GC (the default for the repro and for the ASP.NET Core service), default GC settings (DATAS)
  • SQL Server 2022 CU27 in Docker 28.3.3 (Docker Desktop, WSL 2) on the same machine, TCP on loopback
  • Microsoft.Data.SqlClient 7.1.1 and 8.0.0-preview1.26313.4

I haven't checked Linux.

Other information

  • Not the SqlClient version: the same net9.0 SqlClient 7.1.1 assembly loads on both runtimes, and 8.0.0-preview1
    shows the same pattern.
  • Not GC: allocations per query are identical. In the full service, time in GC and GC counts were also about the
    same.
  • Not ASP.NET Core: in the full service, the ASP.NET Core pipeline on TestServer, with the data layer stubbed out,
    was cheaper per request on .NET 11.
  • Broader than native SNI: native SNI completes I/O through the thread pool's I/O completion port, while managed SNI
    uses Socket async I/O. Both regress at 16 workers, so the cost may be in async I/O completion or continuation
    dispatch generally, rather than in one of the two.
  • Possibly related: Performance Improvements in .NET 11
    describes a change to how overlapped I/O completions are signaled on Windows. I haven't been able to connect it to this.
  • Not profiled at the OS level: I couldn't take an ETW CPU profile (that needs an elevated session). The EventPipe
    sample profiler attributes busy samples differently on the two runtimes (.NET 10 reports PollGC and safepoint frames,
    .NET 11 the actual leaf frames), so those profiles don't compare. I'm happy to collect a trace if you tell me what
    would help.

Activity

  1. added
    untriaged
    on Nov 10, 2026
  2. MihuBot commented on Nov 10, 2026

    @MihuBot

    cc: @dotnet/ncl

  3. dotnet-policy-service commented on Nov 10, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @karelz, @dotnet/ncl
    See info in area-owners.md if you want to be subscribed.

  4. hez2010 commented on Nov 11, 2026

    @hez2010
    Contributor

    Might be related: #135738

    We found there's so much CPU time wasted in spurious spinning.

  5. MichalPetryka commented on Nov 11, 2026

    @MichalPetryka
    Contributor

    Might be related: #135738

    We found there's so much CPU time wasted in spurious spinning.

    The repro is not on runtime async.

  6. added
    tenet-performance
    on Nov 11, 2026
  7. hez2010 commented on Nov 11, 2026

    @hez2010
    Contributor

    Might be related: #135738

    We found there's so much CPU time wasted in spurious spinning.

    The repro is not on runtime async.

    The issue I linked is unrelated to runtime async, but the thread pool scheduling. Though the repro is using runtime async.

  8. paulmedynski commented on Nov 11, 2026

    @paulmedynski

    Linux comparison: regression not reproduced

    I ran the same query-loop repro on Linux/WSL2 with SqlClient 7.1.1. In this environment, .NET 11 did not show the CPU-per-query increase reported above on Windows.

    The method matches the original repro: Release builds from the same source, a 100,000-row table, pooled connections, Server GC, a 5-second warm-up followed by a 15-second measurement, and alternating .NET 10/.NET 11 processes. There were three rounds at each concurrency, with every process pinned to logical CPUs 0-7 using taskset before runtime startup; Environment.ProcessorCount was 8. All 12 measurements completed with zero errors. Linux uses managed networking; MARS was off.

    CPU comparison with the original Windows results

    Process CPU us/query: arithmetic mean, with min-max in brackets. Change is .NET 11 relative to .NET 10.

    Environment Networking Workers .NET 10.0.15 .NET 11.0.0 Change Runs
    Original Windows native SNI 4 79.7 [75.8-86.7] 108.3 [97.1-121.5] +36% 3 + 3
    Original Windows native SNI 16 67.6 [62.7-70.3] 82.8 [78.3-88.9] +22% 3 + 3
    Original Windows managed 4 93.0 [86.9-99.1] 97.3 [94.5-100.0] +5% 2 + 2
    Original Windows managed 16 73.5 [70.1-76.8] 91.1 [90.8-91.3] +24% 2 + 2
    Linux/WSL2 managed 4 214.6 [199.1-226.6] 197.9 [195.6-201.2] -7.8% 3 + 3
    Linux/WSL2 managed 16 178.7 [172.2-183.8] 173.2 [172.6-174.2] -3.1% 3 + 3

    The managed-networking rows are the closest comparison: Windows still regressed by 24% at 16 workers after switching away from native SNI, whereas Linux did not regress. This suggests investigating Windows-specific behavior shared by the two networking paths, rather than assuming either native SNI alone or an OS-independent async regression. It does not identify a root cause.

    Linux throughput and allocations

    Arithmetic means of the same three runs:

    Workers .NET 10 queries/s .NET 11 queries/s .NET 10 B/query .NET 11 B/query
    4 8,519 8,756 5,939 5,924
    16 12,553 12,628 5,967 5,908

    Linux configuration and reproduction

    • Debian GNU/Linux 13 (trixie), x64, WSL2 kernel 6.18.58.1-microsoft-standard-WSL2.
    • AMD Ryzen 7 PRO 8840HS; 16 logical CPUs visible to Linux, with each benchmark process pinned to CPUs 0-7.
    • SDK 11.0.100; runtimes .NET 10.0.15 and .NET 11.0.0.
    • SqlClient 7.1.1 on both runtimes, managed networking, default GC settings with Server GC enabled.
    • SQL Server 2022 CU16 (16.0.4165.4) in local Docker, connected directly to the container's bridge IP on port 1433. The published host port intermittently produced pre-login handshake timeouts, so those failed runs were excluded and the full three-round comparison was run through the direct bridge connection.
    • Packages restored from the public SqlClient feed below; builds completed with zero warnings and errors.

    With REPRO_CONNECTION_STRING pointing at that SQL Server:

    dotnet restore --source https://sqlclientdrivers.pkgs.visualstudio.com/public/_packaging/sqlclient/nuget/v3/index.json
    dotnet run --no-restore -c Release -f net11.0 -- --setup
    pwsh -NoLogo -NoProfile -File ./run.ps1 -NoRestore -Rounds 3 -Seconds 15

    Conclusion: Linux does not appear to have the reported problem in this tested configuration. The Linux per-run CPU ranges overlap, so the lower means should not be treated as proof of a performance improvement. This is not a controlled OS-only comparison: the Windows results used an Intel i9-12900KF, .NET 10.0.14, SQL Server 2022 CU27, and different networking/host conditions; this Linux machine was not dedicated to benchmarking. I have not tested SqlClient 8.0.0-preview1 on Linux. Matching hardware and runtime patches, followed by profiling the Windows case, would be needed to isolate the cause.

  9. coderb commented on Nov 12, 2026

    @coderb

    Reproduced on Linux and Windows; the extra CPU is thread pool spinning

    I reproduced this with the same query loop as the repro: a pooled OpenAsync, one row by primary key with ExecuteReaderAsync/ReadAsync, then close; N workers in a closed loop; a 5 s warm-up. Details:

    • SqlClient 7.1.1. Both runtimes load the identical Microsoft.Data.SqlClient.dll (same MD5).
    • The table has three int/smallint columns keyed by an int, ~1.8M rows, read at random keys.
    • Workstation GC, no CPU pinning. Both clients have 24 logical CPUs.
    • CPU is the client process's own user and kernel time, divided by the queries completed in the measured window.

    The mechanism and what a fix needs are in #135738, so this comment is the data.

    Linux: x64, 24 logical CPUs, kernel 7.0, managed SNI, minimal console app

    4 workers, 8 s measured windows, runtimes alternated. Mean CPU µs per query (user / kernel), and queries/s:

    .NET 10.0.15 .NET 11.0.0
    default 53.7 (39.9 / 13.8), 65.6k q/s, 3 runs 80.8 (72.7 / 8.1), 61.8k q/s, 5 runs
    DOTNET_ThreadPool_SpuriousDispatchNoSpinThreshold=0 31.8 (23.8 / 8.0), 66.9k q/s, 2 runs
    DOTNET_ThreadPool_UnfairSemaphoreSpinLimit=0 28.0 (18.3 / 9.7), 60.0k q/s, 2 runs 21.4 (12.9 / 8.5), 67.5k q/s, 3 runs

    16 workers, one run each:

    .NET 10.0.15 .NET 11.0.0
    default 53.1 (40.2 / 12.9), 128.5k q/s 58.6 (51.1 / 7.5), 124.1k q/s
    SpuriousDispatchNoSpinThreshold=0 28.7 (20.4 / 8.3), 137.4k q/s
    UnfairSemaphoreSpinLimit=0 33.6 (23.3 / 10.3), 127.5k q/s 24.6 (16.2 / 8.4), 140.5k q/s
    Per-run values, 4 workers
    • .NET 10 default: 52.5, 55.3, 53.3
    • .NET 11 default: 81.2, 78.9, 80.0, 82.9, 80.8
    • .NET 11, spurious threshold 0: 33.6, 30.0
    • .NET 11, spin limit 0: 21.4, 20.4, 22.5
    • .NET 10, spin limit 0: 28.2, 27.7

    Allocations per query and thread pool work items per query are the same on both runtimes. So this reproduces on Linux (+50% at 4 workers, +10% at 16), and with either knob .NET 11 costs less than .NET 10.

    Because the server shares this machine, the client's spinning also competes with it for cores. The throughput figures include that effect; the CPU figures are the client's alone.

    Windows: x64 hybrid CPU (performance and efficiency cores, no SMT), 24 logical CPUs, native SNI (default)

    The same loop ran inside a larger console app, otherwise idle during the test. 4 workers, 3 × 10 s rounds per run, 2 passes alternated, no pinning, so pool threads ran on both core types. Mean CPU µs per query (user / kernel):

    .NET 10.0.15 .NET 11.0.0 change
    default 37.0 (26.3 / 10.7) 77.8 (68.5 / 9.3) +110%
    UnfairSemaphoreSpinLimit=0 18.2 (8.7 / 9.5) 27.7 (16.8 / 10.9) +52%
    Per-round values
    • .NET 10 default: 36.8, 36.4, 37.8 / 36.2, 36.9, 37.7
    • .NET 10 spin 0: 17.8, 17.2, 18.8 / 20.1, 17.5, 18.0
    • .NET 11 default: 74.7, 80.7, 80.0 / 74.3, 79.2, 78.0
    • .NET 11 spin 0: 23.2, 23.6, 24.3 / 29.7, 32.3, 33.1

    Throughput is 29–35k queries/s in every configuration. Allocations are 4,744 B/query on .NET 10 and 4,736 B/query on .NET 11.

    Most of the Windows regression is the same spinning, in user mode. Unlike Linux, some remains with spinning off: +30% in pass 1 and +74% in pass 2, also in user time. That matches your observation that spinning off didn't close the gap in your service. Pass 2's spread suggests core placement plays a part on this hybrid CPU, so I wouldn't size the remainder from these runs.

    Not yet run on Windows: SpuriousDispatchNoSpinThreshold=0, managed SNI, and a run pinned to the P-cores.

  10. self-assigned this
    on Nov 18, 2026
  11. dotnet-policy-service commented on Nov 18, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @VSadov
    See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Threadingtenet-performanceuntriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions