littledivy / duckdb

blazing fast duckdb bindings for deno
https://deno.land/x/duckdb
Apache License 2.0
25 stars 6 forks source link

perf improvement for prepared query #6

Open billywhizz opened 11 months ago

billywhizz commented 11 months ago

I did some benchmarking on lo against this and, after understanding what the code here is doing, these changes should result in a ~20% improvement in throughput for this simple bench. i tested on 0.4.0 of duckdb shared library and using this command to run:

DENO_DUCKDB_DEV=1 LD_PRELOAD=../duckdb/0.4.0/libduckdb.so nice -n 20 taskset --cpu-list 0 deno run -A --unstable test.js

i see 60k rps for these changes, ~51k rps for HEAD.

Bun with @evan/duckdb is 49k rps for the same bench on my setup. Bun is also ~50 MB more memory usage.

import { open } from "./mod.ts";

const db = open(":memory:");

const connection = db.connect();

connection.query('CREATE TABLE integers(i INTEGER, j INTEGER);');
connection.query('INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);');

const prepared = connection.prepare('SELECT * FROM integers;');

const runs = 100000

while (1) {
  const start = Date.now()
  for (let i = 0; i < runs; i++) {
    prepared.query()    
  }
  const elapsed = Date.now() - start
  const rate = runs / (elapsed / 1000)
  const ms_iter = elapsed / runs
  const { rss } = Deno.memoryUsage()
  console.log(`runs ${runs} rate ${rate} ms_iter ${ms_iter} rss ${rss}`)
}

connection.close();
db.close();

there is further work to do be done to apply this to the other methods and i need to check to see if this doesn't break something existing, so just submitting as a draft for discussion for now.

littledivy commented 9 months ago

Hey @billywhizz Is this ready for review? Sorry for the late reply, I might have missed this in the notifcations

billywhizz commented 9 months ago

Hey @billywhizz Is this ready for review? Sorry for the late reply, I might have missed this in the notifcations

i'll have a look again. has been a while since i looked at it! :+1: