Skip to content

NpgsqlRest 4.1 Against 3.21, PostgREST and Hand-Written Code ​

Benchmark · November 2026 · NpgsqlRest

Before you trust these numbers

  • The author of NpgsqlRest runs this benchmark, and NpgsqlRest is one of the services in it.
  • The analysis was written with AI assistance from the raw data, then reviewed and edited.
  • Every test ran once, on one machine. Treat differences of a few percent as a tie.
  • Everything is public so you can check it: the code of every service, the data, and everything that went wrong, and how to run it yourself. Corrections and pull requests are welcome.

This benchmark is run by the author of NpgsqlRest, which is one reason everything about it is public. Eight of the 31 services are NpgsqlRest: two versions (3.21.0 from July, and 4.1.0), two builds (native AOT and JIT) and two ways to define endpoints (PostgreSQL functions, and plain SQL files).

Between the two versions, the path a request takes was rebuilt: responses are written straight into the HTTP response as rows arrive, the request context and the routine go to PostgreSQL in one round trip, pooled connections are reset only when an endpoint needs it, and the runtime moved from .NET 10 to .NET 11 with Npgsql 11. The 3.21.0 services run the same images as in July, so they are also this round's controls.

This page answers four questions:

  1. Is version 4.1 better than 3.21?
  2. AOT or JIT build?
  3. Endpoints as functions or as SQL files?
  4. How does it compare with PostgREST, Hasura and PostGraphile, and with code written by hand?

The answers, in short

  • 4.1 against 3.21: a request needs 20% to 32% less CPU and the service uses 18% to 30% less memory. Large responses are about twice as fast; other requests are about as fast as before.
  • AOT or JIT: JIT is about 5% faster under constant load. AOT starts four times sooner and uses about 40% less memory.
  • Functions or SQL files: the same speed. Choose by how you like to work.
  • Against the others: about 2.7 times the requests of PostgREST, about 4 times those of Hasura and PostGraphile, and level with .NET code written by hand.

What is compared ​

Eight NpgsqlRest services, from three choices:

ChoiceThe two options
Version3.21.0 (the same images as in July) and 4.1.0
BuildAOT: a native executable, no .NET runtime needed. JIT: runs on the .NET runtime
EndpointsPostgreSQL functions, or plain .sql files

None of them has endpoint code: the service is a configuration file (appsettings.json), and the endpoints are the functions or the SQL files. Each has 4 CPU cores.

Question 1: is 4.1 better than 3.21? ​

Pick a test and compare. For each of the four variants, the grey bar is version 3.21 and the purple bar is version 4.1. The label on the right says, in plain words, how 4.1 did.

Kind of test
Users at the same time
Size of the response
Show

Requests per second — Large payload, 25 users, 100 KB

3.21 4.1 How many requests were answered per second. More is better. The label on the right says how 4.1 did against 3.21.

AOT, functions
3.212,574req/s
4.18,371req/s
+225% better
JIT, functions
3.213,289req/s
4.18,528req/s
+159% better
AOT, SQL files
3.212,446req/s
4.18,617req/s
+252% better
JIT, SQL files
3.213,210req/s
4.18,786req/s
+174% better

The code of this test:the script that sends the requests · the PostgreSQL function it calls · the same as a SQL file. Click 3.21 ↗ or 4.1 ↗ next to a bar to open that service's own code for this test.

Things worth trying in the chart above:

  • Large payload (where the chart starts): the biggest change of the release. Then switch to "Memory".
  • Data types, 100 users, "Requests per CPU core": the same throughput for much less processor.
  • Table insert: the one kind of test where 4.1 is a little behind 3.21.

The averages ​

The change from 3.21 to 4.1 over all 44 tests. A plus is good for the first two columns; a minus is good for the last two.

Requests/sRequests/s per CPU corePeak memoryp99 latency
AOT, functions+8.0%+25%−30%−9%
JIT, functions+6.5%+47%−23%−8%
AOT, SQL files+7.1%+25%−25%−10%
JIT, SQL files+7.0%+46%−18%−7%
  • A request costs a quarter to a half less CPU. Requests per core are up +25% for the AOT builds and +47% for the JIT builds.
  • Memory is down 18% to 30%.
  • Throughput is up +7% to +8% on average, and that average hides the shape of it. Almost all of the gain is in large responses, where 4.1 is 1.7 to 2.2 times as fast, and in list pages for the JIT builds (+15%). Elsewhere the two versions are within a few percent, which is what happens when the limit is somewhere else (see what limited the tests).
  • Inserts are a few percent slower on 4.1, most with the AOT builds (−7%). It is the one place where the new version is behind the old one by more than a tie.
  • Tail latency is 7% to 10% lower.
The same numbers for each kind of test

Requests per second, 4.1 against 3.21

Kind of testAOT, functionsJIT, functionsAOT, SQL filesJIT, SQL files
Data types+2%+1%+1%+1%
Minimal request−4%+2%−3%+1%
POST body+0%+0%−0%+0%
Nested JSON+1%+1%+1%+1%
Large payload+125%+71%+116%+73%
Many parameters−1%+6%−0%+6%
Table lookup−1%+1%−1%+5%
Table list page+2%+15%+1%+14%
Table insert−7%−3%−6%−1%
All 44 tests+8%+7%+7%+7%

Requests per CPU core, 4.1 against 3.21

Kind of testAOT, functionsJIT, functionsAOT, SQL filesJIT, SQL files
Data types+33%+62%+31%+60%
Minimal request+2%+13%+5%+13%
POST body+18%+44%+19%+44%
Nested JSON+18%+48%+15%+47%
Large payload+114%+99%+119%+107%
Many parameters+0%+16%+4%+14%
Table lookup+4%+16%+4%+13%
Table list page+6%+31%+8%+30%
Table insert−0%+11%+2%+14%
All 44 tests+25%+47%+25%+46%

Memory, by kind of test ​

Peak memory of the container during the tests of each type, in MB: 3.21 → 4.1.

Kind of testAOT, functionsJIT, functionsAOT, SQL filesJIT, SQL files
Data types165 → 105166 → 147177 → 104160 → 156
Minimal request109 → 104179 → 167115 → 108163 → 161
POST body125 → 83166 → 163110 → 74153 → 142
Nested JSON101 → 65140 → 12996 → 82149 → 130
Large payload365 → 133422 → 204436 → 179542 → 224
Many parameters305 → 128394 → 197347 → 190394 → 191
Table lookup198 → 97280 → 195124 → 89223 → 192
Table list page143 → 88280 → 152126 → 90208 → 166
Table insert158 → 118252 → 157166 → 110228 → 154
Highest in any test365 → 133422 → 204436 → 190542 → 224

Large responses ​

A 100 KB response at 25 users at the same time is the single largest difference between two versions of any service in this round: 2,574 requests per second on 3.21 (AOT, functions) and 8,371 on 4.1. Version 3.21 read the whole value from PostgreSQL, built the response in memory and then sent it. Version 4.1 forwards it as it arrives.

Requests per second, large payload, 25 users, 100 KB: NpgsqlRest and five others

↑ longer bar is betterEach bar is how many requests that service answered per second in this test.

  1. 1NpgsqlRest 4.1 JIT · SQL files8,786req/s
  2. 2NpgsqlRest 4.1 AOT · SQL files8,617req/s
  3. 3Fastify 5.128,584req/s
  4. 4NpgsqlRest 4.1 JIT · functions8,528req/s
  5. 5NpgsqlRest 4.1 AOT · functions8,371req/s
  6. 6Go 1.27 · net/http8,251req/s
  7. 7Actix-web 4.20 (Rust)8,118req/s
  8. 8.NET 11 · plain Npgsql5,762req/s
  9. 9PostgREST 16.64,211req/s
  10. 10NpgsqlRest 3.21 JIT · functions3,289req/s
  11. 11NpgsqlRest 3.21 JIT · SQL files3,210req/s
  12. 12NpgsqlRest 3.21 AOT · functions2,574req/s
  13. 13NpgsqlRest 3.21 AOT · SQL files2,446req/s

Question 2: AOT or JIT? ​

NpgsqlRest ships as a native AOT executable and as a JIT build. The AOT build against the JIT build of the same 4.1.0, over all 44 tests:

Requests/sRequests/s per CPU corePeak memoryp99 latency
AOT against JIT, functions−5.0%−13%−44%+0%
AOT against JIT, SQL files−5.9%−14%−41%+6%
ServiceFirst answer after msIdle memory MBPeak memory MBImage MB
NpgsqlRest 4.1 AOT · functions28722.813359
NpgsqlRest 4.1 JIT · functions1,21338.9204123
NpgsqlRest 4.1 AOT · SQL files24423.919059
NpgsqlRest 4.1 JIT · SQL files1,25439.4224123

JIT is faster under sustained load, AOT is smaller and starts sooner. The JIT build has 5% more throughput on average, because the JIT compiler optimizes the hot path with what it learns while running. The AOT build answers its first request about 4 times sooner, idles on 23 MB instead of 39, peaks lower, and its image is half the size. For a service that is scaled up and down or started on demand, AOT; for a long-running one that is always busy, JIT.

Question 3: functions or SQL files? ​

An endpoint can be a PostgreSQL function, or a .sql file with the statement in it. SQL files against functions on 4.1.0:

Requests/sRequests/s per CPU corePeak memoryp99 latency
SQL files against functions, AOT+2.7%+1%+6%+1%
SQL files against functions, JIT+3.6%+1%+1%−4%

They are the same within a few percent (+2.7% and +3.6% in throughput). Choose by how you want to work, not by speed. In this benchmark each SQL file holds the same statement as the body of the matching function, so this compares two ways to run the same SQL: through a function call, or directly.

Question 4: how does it compare with the others? ​

Against the other generated APIs ​

PostgREST, Hasura and PostGraphile also turn a PostgreSQL schema into an API without endpoint code. Pick a test to see all of them with the four NpgsqlRest 4.1 variants:

Kind of test
Users at the same time
Rows in the response
Show
Requests per second: Data types, 100 users, 10 rows

↑ longer bar is betterHow many requests each service answered per second, with 100 users sending requests at the same time.

  1. 1NpgsqlRest 4.1 JIT · SQL files16,948req/sk6 limit
  2. 2NpgsqlRest 4.1 JIT · functions15,940req/sk6 limit
  3. 3NpgsqlRest 4.1 AOT · SQL files15,861req/sk6 limit
  4. 4NpgsqlRest 4.1 AOT · functions15,681req/sk6 limit
  5. 5PostgREST 16.64,027req/s
  6. 6PostGraphile 5.2 (GraphQL)2,465req/sk6 limit
  7. 7Hasura 2.50 (GraphQL)1,767req/s

The code of this test:the script that sends the requests · the PostgreSQL function it calls · the same as a SQL file. Click a service's name (↗) to open its own code for this test.

How many times as many requests per second NpgsqlRest 4.1 (AOT, functions) answered, for each kind of test. "2.7×" means 2.7 times as many.

Kind of testPostgREST 16.6Hasura 2.50PostGraphile 5.2
Data types2.0×2.8×5.3×
Minimal request7.0×13.9×4.5×
POST body2.3×4.5×3.5×
Nested JSON1.9×3.6×4.7×
Large payload1.5×1.4×1.3×
Many parameters9.2×13.7×4.2×
Table lookup6.7×14.6×4.6×
Table list page5.4×10.7×4.9×
Table insert5.4×13.6×4.3×
All 44 tests2.7×4.4×4.1×
ServicePosition on the leaderboard (of 31)Peak memory MBIdle memory MBFirst answer after msImage MBRequests/s per CPU core
NpgsqlRest 4.1 AOT · functions1413322.8287593,539
PostgREST 16.6261427.2165201,508
Hasura 2.50 (GraphQL)282,571159.12,365206942
PostGraphile 5.2 (GraphQL)291,309372.2943220832

Two things to keep in mind when reading this:

  • PostgREST is smaller at rest. Its image is a third of the size and it idles on 7 MB against 23. Under load the two use about the same memory (the most in any test: 142 MB for PostgREST, 133 MB for NpgsqlRest).
  • PostgREST was run twice. In the first run it had 10 database connections instead of 100, by a mistake in this benchmark's setup. These are the results with 100. What happened.
  • Hasura and PostGraphile speak GraphQL, which is a different protocol with different strengths: a client asks for exactly the fields it wants, in one request across several objects. In this benchmark every request is a POST with a query document that the server has to parse and plan before it reaches PostgreSQL, and Hasura calls wrapper functions because it cannot expose a function that returns TABLE(...). It is the same data from the same functions, asked for the way each product is used.

Against code written by hand ​

NpgsqlRest 4.1 (AOT, functions) against services where every endpoint is written by hand, over all 44 tests:

NpgsqlRest 4.1 AOT againstRequests/sRequests/s per CPU corePeak memoryp99 latency
.NET 11, plain Npgsql−0.6%−1%−38%−6%
.NET 11, Dapper+1.0%+2%−42%−5%
.NET 11, EF Core+57.1%+101%−54%−29%
Go, net/http−18.7%−4%+97%+17%
Rust, Actix-web−1.0%−10%+128%+6%
Java, Spring Boot+25.7%+43%−94%−27%
Node.js, Fastify+11.3%+35%−84%+5%
Bun−10.9%−3%−57%+9%
Python, FastAPI+216.7%+352%−71%−58%
  • Level with hand-written .NET on plain Npgsql and Dapper, with about 40% less memory. The generated API costs nothing over writing it by hand on the same platform. More on the .NET page.
  • Behind Go by 19% in throughput, with about twice the memory. Go is the leader of this round.
  • Level with the Actix-web service in throughput (−1.0%), which uses 12% less CPU per request. The two Rust services in this benchmark build each SQL statement as text instead of preparing it, so a tuned Rust service would do better than these numbers.

The code ​

What somebody has to write for the nine endpoints of this benchmark, in non-blank lines:

ServiceOwn code and configurationSQLTotalPosition on the leaderboard (of 31)Its code
NpgsqlRest 4.1 AOT · SQL files29135 (SQL files)1649appsettings.json
NpgsqlRest 4.1 AOT · functions21205 (functions)22614appsettings.json
PostgREST 16.616205 (functions)22126postgrest.conf
PostGraphile 5.2 (GraphQL)44205 (functions)24929graphile.config.mjs
Hasura 2.50 (GraphQL)86277 (functions and wrappers)36328databases.yaml
.NET 11 · EF Core116205 (functions)32124Program.cs
.NET 11 · Dapper155205 (functions)36016Program.cs
.NET 11 · plain Npgsql281205 (functions)48613Program.cs
Fastify 5.12129205 (functions)33420app.js
Go 1.27 · net/http408205 (functions)6132main.go

The whole NpgsqlRest service is a 21-line configuration file (appsettings.json) that says where the database is and which schema to expose. The endpoints are the functions themselves, with one comment each (HTTP GET /api/perf-test). With SQL files there is not even a function: each file is a statement with a comment on top. The same nine endpoints are 281 lines of C# with plain Npgsql and 408 lines of Go, in addition to the same functions. All counts: Code you write.

All eight NpgsqlRest services ​

Pick a test to see the eight side by side.

Kind of test
Users at the same time
Rows in the response
Show
Requests per second: Data types, 100 users, 10 rows

↑ longer bar is betterHow many requests each service answered per second, with 100 users sending requests at the same time.

  1. 1NpgsqlRest 4.1 JIT · SQL files16,948req/sk6 limit
  2. 2NpgsqlRest 4.1 JIT · functions15,940req/sk6 limit
  3. 3NpgsqlRest 3.21 JIT · SQL files15,934req/s
  4. 4NpgsqlRest 4.1 AOT · SQL files15,861req/sk6 limit
  5. 5NpgsqlRest 4.1 AOT · functions15,681req/sk6 limit
  6. 6NpgsqlRest 3.21 JIT · functions15,478req/s
  7. 7NpgsqlRest 3.21 AOT · SQL files15,316req/s
  8. 8NpgsqlRest 3.21 AOT · functions15,171req/s

The code of this test:the script that sends the requests · the PostgreSQL function it calls · the same as a SQL file. Click a service's name (↗) to open its own code for this test.

ServicePosition on the leaderboard (of 31)Speed scoreTests where it was the fastest (of 44)Requests/s per CPU corePeak memory MB
NpgsqlRest 4.1 JIT · SQL files482%64,131224
NpgsqlRest 4.1 JIT · functions679%14,079204
NpgsqlRest 3.21 JIT · SQL files777%32,829542
NpgsqlRest 4.1 AOT · SQL files977%03,557190
NpgsqlRest 4.1 AOT · functions1475%03,539133
NpgsqlRest 3.21 JIT · functions1575%02,779422
NpgsqlRest 3.21 AOT · SQL files1773%02,842436
NpgsqlRest 3.21 AOT · functions1971%02,828365

Previous: ← .NET 10 and .NET 11 · Next: Compare Any Two →

Comments