Skip to content

Add batched row iteration via allBatched(batchSize) - #233

Draft
xoxohorses wants to merge 6 commits into
tursodatabase:mainfrom
xoxohorses:jy--codex-batched-row-reads
Draft

Add batched row iteration via allBatched(batchSize)#233
xoxohorses wants to merge 6 commits into
tursodatabase:mainfrom
xoxohorses:jy--codex-batched-row-reads

Conversation

@xoxohorses

@xoxohorses xoxohorses commented Sep 12, 2026

Copy link
Copy Markdown

Description

Adds RowsIterator.nextBatch(maxRows) in Rust and exposes Statement.allBatched(batchSize, ...bindParameters) in the promise API.

This was motivated by a production trace of a simple ordered query that returned 9,088 rows: about 280 ms of its 350 ms p50 was attributed to SQLite processing. For that result size, the current all() path makes 9,088 asynchronous Rust-to-JavaScript round trips. Batching keeps SQLite's row-at-a-time stepping inside Rust and resolves one Promise per batch, which removes most of the boundary and Promise overhead.

Benchmark

The public benchmark prepares the table before timing, reads the same rows through each API, and validates every result. These averages were measured on Node 22.13.1 for x64 Linux with an Intel Xeon Platinum 8375C CPU.

Rows all() allBatched(250) Speedup
1,000 15.213 ms 1.292 ms 11.77x
10,000 151 ms 11.417 ms 13.25x
100,000 1.535 s 164 ms 9.36x
1,000,000 15.780 s 1.132 s 13.94x

Benchmark source: https://github.com/xoxohorses/libsql-js/blob/e64ee564e60226e076c243342821ce90829158b5/perf/perf-libsql-batched-rows.js

How was this change tested?

  • Automated test (unit, integration, etc.)
  • Manual test (provide reproducible testing steps below)

Built the native module, then ran the public benchmark across 1,000, 10,000, 100,000, and 1,000,000 returned rows. The benchmark validated each result set.

[written by Codex]

@xoxohorses xoxohorses closed this Sep 12, 2026
@xoxohorses
xoxohorses deleted the jy--codex-batched-row-reads branch September 12, 2026 01:28
@xoxohorses
xoxohorses restored the jy--codex-batched-row-reads branch September 12, 2026 01:44
@xoxohorses xoxohorses reopened this Sep 12, 2026
@xoxohorses xoxohorses changed the title [Promise API] Add batched row iteration Add batched row iteration Sep 12, 2026
@xoxohorses xoxohorses changed the title Add batched row iteration Add batched row iteration via allBatched(batchSize) Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant