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
28 lines
914 B
TypeScript
28 lines
914 B
TypeScript
import { bench, describe } from 'vitest'
|
|
import { InMemoryKVDriver } from '../src/kv/memory.js'
|
|
import { KVStorage } from '../src/kv/node.js'
|
|
import { KVEventStorage } from '../src/events/kv.js'
|
|
|
|
const events = new KVEventStorage(new KVStorage(new InMemoryKVDriver()))
|
|
const streams = events.child('streams')
|
|
const long = streams.child('long')
|
|
for (let i = 0; i < 10_000; i++) await long.append([{ type: 'tick', i }])
|
|
let s = 0
|
|
|
|
describe('events', () => {
|
|
bench('append 1 event (warm head cache)', async () => {
|
|
await streams.append(`s${s++ % 1000}`, [{ type: 'e' }])
|
|
})
|
|
bench('read 100 events from version 5000 of 10k', async () => {
|
|
for await (const _ of long.read({ from: 5000, limit: 100 })) {
|
|
}
|
|
})
|
|
bench('read full 10k-event stream', async () => {
|
|
for await (const _ of long.read()) {
|
|
}
|
|
})
|
|
bench('version() (cold head lookup)', async () => {
|
|
await long.version()
|
|
})
|
|
})
|