logoalt Hacker News

gavinrayyesterday at 6:24 PM6 repliesview on HN

One of the biggest things preventing software like SQL DB's from being written in TypeScript is the lack of proper threading.

I genuinely think you could write a competitively-performant multi-threaded DB in Bun + TS if you had shared-heap threads and fast atomics/locking primitives.


Replies

jerfyesterday at 8:03 PM

"I genuinely think you could write a competitively-performant multi-threaded DB in Bun + TS if you had shared-heap threads and fast atomics/locking primitives."

Not likely. Databases that attain any significant use in the field end up getting optimized to the n'th degree because they're the bottleneck of the entire system of every system they get put into. Javascript runs on the "5-10x slower than C" language tier. Personally I think even picking Go, in the "2x slower than C" tier, is a huge mistake, though a few people seem to be doing OK with it. I don't think you can call it "competitive" when your C++ or Rust competition is consuming a factor of magnitude less resources.

WASM DBs, maybe, especially as it continues to mature. Not Javascript.

show 2 replies
n_eyesterday at 7:11 PM

You have web workers, and for shared memory and synchronisation respectively SharedArrayBuffer and the Atomics namespace.

show 1 reply
ozgrakkurttoday at 1:47 AM

This sounds pretty insane if you wrote any database code that needs to care about memory management at all

Groxxyesterday at 7:14 PM

Are you hoping to, like, run postgres in nodejs or something?

You can get parallelism with web workers and shove sqlite over there if you like, e.g. for running more intensive queries. Beyond that I kinda don't see much of a reason to use JS for databases, except maybe for isolation (e.g. via wasm).

piterrroyesterday at 6:34 PM

I honestly should print that comment and hang it on a wall.

> …competitively-performant… Care to explain competitively to what?

forrestthewoodsyesterday at 6:32 PM

…but why? JS/TS does not seem like the right tool for the job?

show 1 reply