blinkdb-js / blinkdb

🗃️ An in-memory JS database optimized for large scale storage on the frontend.
https://blinkdb.io
MIT License
119 stars 10 forks source link

insertMany very slow #14

Closed maradotwebp closed 1 year ago

maradotwebp commented 1 year ago

The insertMany is currently very slow in benchmarks. That doesn't seem very realistic.

blinkdb/insert-many.ts --- lokijs is 417.44x faster than blinkdb
┌─────────┬───────────┬────────────────────┬────────────────────┬──────────┬─────────┐
│ (index) │   name    │      ops/sec       │ Average Time (ns)  │  Margin  │ Samples │
├─────────┼───────────┼────────────────────┼────────────────────┼──────────┼─────────┤
│    0    │ 'lokijs'  │ 203398.47530091717 │ 4916.457699697863  │ '±1.64%' │ 101700  │
│    1    │ 'blinkdb' │ 487.25611966443955 │ 2052308.7543542264 │ '±4.94%' │   244   │
└─────────┴───────────┴────────────────────┴────────────────────┴──────────┴─────────┘

blinkdb/upsert-many.ts --- lokijs is 3.87x faster than blinkdb
┌─────────┬───────────┬────────────────────┬────────────────────┬──────────┬─────────┐
│ (index) │   name    │      ops/sec       │ Average Time (ns)  │  Margin  │ Samples │
├─────────┼───────────┼────────────────────┼────────────────────┼──────────┼─────────┤
│    0    │ 'lokijs'  │ 1633.0642639853138 │ 612345.7735579922  │ '±4.32%' │   817   │
│    1    │ 'blinkdb' │ 421.87318580370237 │ 2370380.5637585605 │ '±7.20%' │   211   │
└─────────┴───────────┴────────────────────┴────────────────────┴──────────┴─────────┘

blinkdb/update.ts --- lokijs is 3.34x faster than blinkdb
┌─────────┬───────────┬────────────────────┬────────────────────┬───────────┬─────────┐
│ (index) │   name    │      ops/sec       │ Average Time (ns)  │  Margin   │ Samples │
├─────────┼───────────┼────────────────────┼────────────────────┼───────────┼─────────┤
│    0    │ 'lokijs'  │ 268725.01220459485 │ 3721.2762287964697 │ '±4.79%'  │ 134364  │
│    1    │ 'blinkdb' │ 80449.77230128765  │ 12430.115976648878 │ '±20.82%' │  40354  │
└─────────┴───────────┴────────────────────┴────────────────────┴───────────┴─────────┘
maradotwebp commented 1 year ago

I fixed an issue with the benchmark displaying incorrect results because errors were swallowed. With the fixed benchmarks, it looks much more realistic:

blinkdb\insert-many.ts --- lokijs is 1.08x faster than blinkdb
┌─────────┬───────────┬────────────────────┬────────────────────┬───────────┬─────────┐
│ (index) │   name    │      ops/sec       │ Average Time (ns)  │  Margin   │ Samples │
├─────────┼───────────┼────────────────────┼────────────────────┼───────────┼─────────┤
│    0    │ 'lokijs'  │ 291.5321492067237  │ 3430153.4246602287 │ '±6.94%'  │   146   │
│    1    │ 'blinkdb' │ 270.58441059913207 │ 3695704.4117426607 │ '±11.84%' │   136   │
└─────────┴───────────┴────────────────────┴────────────────────┴───────────┴─────────┘

blinkdb\upsert-many.ts --- lokijs is 1.44x faster than blinkdb
┌─────────┬───────────┬────────────────────┬────────────────────┬───────────┬─────────┐
│ (index) │   name    │      ops/sec       │ Average Time (ns)  │  Margin   │ Samples │
├─────────┼───────────┼────────────────────┼────────────────────┼───────────┼─────────┤
│    0    │ 'lokijs'  │ 276.56897678633635 │ 3615734.5325558735 │ '±6.06%'  │   139   │
│    1    │ 'blinkdb' │ 191.67679458889793 │  5217115.6250018   │ '±14.38%' │   96    │
└─────────┴───────────┴────────────────────┴────────────────────┴───────────┴─────────┘

blinkdb\update.ts --- lokijs is 6.19x faster than blinkdb
┌─────────┬───────────┬────────────────────┬────────────────────┬───────────┬─────────┐
│ (index) │   name    │      ops/sec       │ Average Time (ns)  │  Margin   │ Samples │
├─────────┼───────────┼────────────────────┼────────────────────┼───────────┼─────────┤
│    0    │ 'lokijs'  │ 780488.9067911205  │ 1281.2481911003335 │ '±14.40%' │ 390245  │
│    1    │ 'blinkdb' │ 126152.36584219857 │ 7926.922284207334  │ '±14.78%' │  63193  │
└─────────┴───────────┴────────────────────┴────────────────────┴───────────┴─────────┘

I'm still looking if I can make insertMany faster in some way.

maradotwebp commented 1 year ago

The performance of insertMany was massively increased in the latest release.