-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Performance: pg VS postgres.js VS Bun.SQL #3391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Actually, I'm benchmarking few days 3 packages in production on real data, with non-trivial raw sql:
I follow not only the number of Postman benchmark, but also from logs of execution time of each query, and also from tracing of DataDog. The only question now is - either I want to deal with We use Prisma in general... but I must have max performance... |
@spaiz if you want use literal string as query try https://www.npmjs.com/package/sql-template-tag import sql from "sql-template-tag";
import pg from "pg";
const id = 10;
pg.query( sql`SELECT * FROM books WHERE id = ${id}` ); |
@cesco69 Yeah, spent half a day for that. It uses esm, I'm using commonjs on node 20... at the end, finally successfully adopted it. Needed to upgrade to nodejs 22 which supports commonjs and esm modules to be used together. |
Thanks for the repor on this! I really appreciate it. This is why it's always good to be suspect of benchmarks and do your own! While its tempting to publish these results in some official capacity I'm not sure about that yet...but I'll keep it in mind & if so, I'll tag ya on the PR to review the docs. :) |
Also did those benchmarks account for heating the functions? v8 does some optimizations and so first N runs of a certain function can be slower than the same amount of runs right after. So it seems best to either run every test as individual process, or let all of them warmup in the beginning, and then actually measure their perfomance. |
Postgres.js claim to be the "Fastest" and link a this benchmark https://github.com/porsager/postgres-benchmarks#results , last update of 4 years ago!!!! Also the benchmark is totally wrong because Postgres.js use prepared statements by default, whereas pg requires setting the name parameter AND don't expose the GC of node, this can also cause random slowdown due to random execution of the GC!
it would be more honest if Postgres.js claim to be "Faster" and not "Fastest" Side note: "prepared statements by default" It looks like a feature to win in benchmarks, |
bun is written in zig, not rust |
Uh oh!
There was an error while loading. Please reload this page.
TL;TR: pg seems fast!
Hi, I've made a small benchmark to compare this library against others that claim to be the fastest: Postgres.js and Bun.SQL.
Inspired by some online benchmarks, here’s the first test:
package.json
index.js
run with
And here are the results:
At first glance, pg seems very slow, but that’s not actually the case. The reason is that Bun and Postgres.js automatically cache prepared statements by default, whereas pg requires setting the name parameter to enable prepared statement caching. If we update the benchmark like this:
pg
actually becomes faster thanpostgres.js
:pg is still slower than Bun.SQL, but that’s mainly because Bun is written in Rust! Maybe compared to pg-native, Bun would lose, but it's not possible to run this benchmark since pg-native only works on Node.js.
I've also run a benchmark with more test cases:
pg
seem very fastIn the "parallel" bench the gap with Bun increases because Bun has the "pipeline mode" active (but also Postgres.js has it)
The text was updated successfully, but these errors were encountered: