tursodatabase / libsql-js

A better-sqlite3 compatible API for libSQL that supports Bun, Deno, and Node
MIT License
169 stars 19 forks source link

Improve performance #121

Open penberg opened 6 days ago

penberg commented 6 days ago

We are still a bit behind better-sqlite3. For example, there's more overhead in get():

penberg@vonneumann libsql-js % node perf/perf-libsql.js

cpu: Apple M1
runtime: node v18.19.0 (arm64-darwin)

benchmark      time (avg)             (min … max)       p75       p99      p999
------------------------------------------------- -----------------------------
• Statement
------------------------------------------------- -----------------------------
get(1)      1'969 ns/iter   (1'911 ns … 2'539 ns)  1'970 ns  2'424 ns  2'539 ns

summary for Statement
  get(1)

penberg@vonneumann libsql-js % node perf/perf-better-sqlite3.js
cpu: Apple M1
runtime: node v18.19.0 (arm64-darwin)

benchmark      time (avg)             (min … max)       p75       p99      p999
------------------------------------------------- -----------------------------
• Statement
------------------------------------------------- -----------------------------
get(1)        587 ns/iter     (555 ns … 1'122 ns)    584 ns    944 ns  1'122 ns

The assumption that a lot of this is memory memory allocations and copies as values are passed between the C, Rust, and JavaScirpt layers. We also suspect that Neon Bindings may be less efficient than better-sqlite3 is which seems to hook into the V8 APIs directly.

Let's improve the benchmarks, profile, and fix performance to be on-par with better-sqlite3.

drewbitt commented 3 days ago

This would be great; think there is most every feature I want here in replacing and improving on better-sqlite3 (once extension support in 0.40 lands), except performance.