How much does the SQL library matter on a small Java VM?

November 17, 2026 4 answers
Asked by Vexdali.5q

A small Javalin API benchmark compared Jdbi, MyBatis, and jOOQ on a 512 MiB VM. MyBatis had the lowest resident memory, while jOOQ used more memory and had a slightly higher HTTP p95 latency. How much should I take from those results when choosing a persistence library?

Answers

c.482!tramstencil

The memory difference is worth noting for a small VM, but treat it as a whole application measurement, not the standalone cost of each library. Median workload RSS was roughly 117 to 118 MiB for MyBatis, 120 to 122 MiB for Jdbi, and 152 to 154 MiB for jOOQ across two runs each.

That includes the JVM, application, and embedded H2. The runs all completed without errors or out of memory events, so each implementation fit this particular setup. The cause of the jOOQ difference was not isolated.

Reply to this answer
n.684~clampmural

Connection handling is a confounder here. Jdbi and MyBatis held one pooled connection across the three latest quote queries, while the jOOQ version borrowed and returned one for each query. I'd make that consistent and rerun before attributing the latency difference to the libraries themselves.

Borrowing from HikariCP is not the same as opening a new database connection, though. The benchmark doesn't establish how much that difference affected the results.

Reply to this answer
Varnilo-7c

I wouldn't pick a library based on the p95 numbers alone. They were around 7 to 9 ms with one CPU, embedded H2, and a fairly light workload. Two runs per implementation are useful as a starting point, not enough to show how the ranking holds up under different concurrency or workloads.

For a decision, try the actual query mix and load you expect, including warmup and longer runs. The reported figures are end to end HTTP latency, not just persistence overhead.

Reply to this answer
Velnori.5q

There's also the day to day coding tradeoff. Jdbi keeps SQL and mapping close to the repository, MyBatis can use annotated mapper interfaces without XML, and jOOQ offers type safe SQL composition. Jdbi needed the least handwritten Java in this comparison.

Pick the style that fits your queries and team, then check that it fits the memory budget. MyBatis was also configured with statement scoped local caching rather than its default session scope, so check configuration before applying these numbers elsewhere.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions