DEV Community

Aurélien Bottazini
Aurélien Bottazini

Posted on

Serve your data blazingly fast with Sqlite3 and Javascript

Serve your data blazingly fast with Sqlite3 and Javascript

I love SQLite3. It is my de-facto database for personal projects. I have seen people import millions of rows per minute. I was stunned to see it used as an NOSQL Database. I adore that you can host SQLite databases everywhere. SQLite3 versatilety is amazing.

I wanted to explore the performance of SQLite3 when it is used with a web server. Indeed with 2022 Europe energy crisis It is vital to find cost efficient solutions.

I experimented with various programming languages: Go, Ruby, JavaScript, Rust.

My goal: get a feel for what is achievable concurrency wise.

I balanced speed with code complexity. I did not want to spend too much time on each implementation. The SQLite queries I used are simple. One insert statement, one query statement. This is not a test to verify SQLite performance. I know SQLite is fast. This is a test to see the blocking impact of SQLite queries on web servers.

The JavaScript results amazed me.

node:

  • With an sqlite insert: 16k requests per second
  • With an sqlite select: 31k requests per second

node-sqlite3

rust:

  • With an sqlite insert: 14k requests per second
  • With an sqlite select: 61k requests per second

rust is slower with inserts but twice as fast with queries.

rust sqlite3

bun.sh (a new javascript runtime):

  • With an sqlite insert: 21k requests per second
  • With an sqlite select: 75k requests per second

bun.sh sqlite3

What? bun.sh is twice as fast on inserts and better on selects.
We live in a time when anyone can serve tens of thousands of requests per second from one server (the one I used is 3 years old).
You don't need a fancy database.
An sqlite3 database hosted on the same host is more than enough.

I remember hearing John Carmack say

The engineering under JavaScript is really pretty phenomenal
Enter fullscreen mode Exit fullscreen mode

bun.sh is a new example of phenomenal engineering for JavaScript.
When you combine all the blazingly fast JavaScript optimisations with Sqlite3 you get performance that is on par with compiled languages.

I imagine I could get rust to be faster.
But that's going to require more work to figure out the implementation details.
bun.sh + SQLite3 are more than enough for all my performance needs.

References

Top comments (0)