M9: benchmarks, chunked sorted map and JSON clone for the in-memory driver
Profiling showed document updates dominated by O(n) sorted-array splices; the chunked map makes inserts O(log n + chunk). Baselines recorded in DESIGN.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017Qxbkp4tA7G5SCWjzWuxmE
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { bench, describe } from 'vitest'
|
||||
import { InMemoryKVDriver } from '../src/kv/memory.js'
|
||||
import { KVStorage } from '../src/kv/node.js'
|
||||
|
||||
// 1k children, each with 100 descendants (100k keys under the node).
|
||||
const db = new KVStorage(new InMemoryKVDriver({ clone: false }))
|
||||
const node = db.child('n')
|
||||
const writes: [string, number][] = []
|
||||
for (let c = 0; c < 1000; c++) {
|
||||
writes.push([`n/c${c}`, c])
|
||||
for (let d = 0; d < 100; d++) writes.push([`n/c${c}/d${d}`, d])
|
||||
}
|
||||
await db.driver.setMany(writes)
|
||||
|
||||
describe('keys() on 1k children x 100 descendants', () => {
|
||||
bench('keys() skip-scan', async () => {
|
||||
let n = 0
|
||||
for await (const _ of node.keys()) n++
|
||||
if (n !== 1000) throw new Error(`expected 1000, got ${n}`)
|
||||
})
|
||||
bench('naive full subtree scan (reference)', async () => {
|
||||
let n = 0
|
||||
for await (const _ of db.driver.scan({ gte: 'n/', lt: 'n0' })) n++
|
||||
if (n !== 101_000) throw new Error(`expected 101000, got ${n}`)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user