-
Notifications
You must be signed in to change notification settings - Fork 49
Batch Promise iterator row reads #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
penberg
merged 14 commits into
tursodatabase:main
from
xoxohorses:jy--codex-batched-row-reads
Sep 18, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0267c5c
Batch async row iteration
xoxohorses 67e2b8c
Harden batched row iteration
xoxohorses 2e5e35a
Add batched row benchmark
xoxohorses 3954178
Benchmark multiple row batch sizes
xoxohorses d8caa75
Keep row count benchmark
xoxohorses 116d3c0
Simplify batched row iteration
xoxohorses e2a5d9d
Batch Promise iterator row reads
xoxohorses e2f0ba0
Inline default row batch size
xoxohorses cd0e069
Inline row value collection
xoxohorses f1cb6b8
Remove stray test whitespace
xoxohorses 1f76a11
Add default row batch size
xoxohorses 1925445
Stop in-flight row batch when iterator is closed
penberg dc6f8bc
Release statement when nextBatch() rejects the batch size
penberg 11c8ea0
Document batchSize as promise API only
penberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Run `npm run build`, then from this directory run: | ||
| // `npm install && node --expose-gc perf-libsql-batched-rows.js` | ||
| import { baseline, bench, group, run } from 'mitata'; | ||
|
|
||
| // Import the parent checkout so this benchmark uses its locally built native module. | ||
| import libsql from '../promise.js'; | ||
|
|
||
| const { connect } = libsql; | ||
|
|
||
| const BATCH_SIZE = 250; | ||
| const ROW_COUNTS = [1_000, 10_000, 100_000, 1_000_000]; | ||
| const MAX_ROW_COUNT = ROW_COUNTS[ROW_COUNTS.length - 1]; | ||
|
|
||
| const db = await connect(':memory:', {}); | ||
| await db.exec(` | ||
| CREATE TABLE benchmark_rows (value INTEGER PRIMARY KEY); | ||
| WITH RECURSIVE numbers(value) AS ( | ||
| SELECT 1 | ||
| UNION ALL | ||
| SELECT value + 1 FROM numbers WHERE value < ${MAX_ROW_COUNT} | ||
| ) | ||
| INSERT INTO benchmark_rows SELECT value FROM numbers; | ||
| `); | ||
|
|
||
| const stmt = await db.prepare(` | ||
| SELECT value | ||
| FROM benchmark_rows | ||
| WHERE value <= ? | ||
| ORDER BY value | ||
| `); | ||
|
|
||
| for (const rowCount of ROW_COUNTS) { | ||
| group(`${rowCount.toLocaleString('en-US')} rows`, () => { | ||
| baseline('all()', async () => { | ||
| validateRows(await stmt.all(rowCount), rowCount); | ||
| }); | ||
| bench(`all() with batchSize ${BATCH_SIZE}`, async () => { | ||
| validateRows(await stmt.all(rowCount, { batchSize: BATCH_SIZE }), rowCount); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| await run({ | ||
| units: false, | ||
| silent: false, | ||
| avg: true, | ||
| json: false, | ||
| colors: process.stdout.isTTY, | ||
| min_max: true, | ||
| percentiles: true, | ||
| }); | ||
|
|
||
| db.close(); | ||
|
|
||
| function validateRows(rows, expectedCount) { | ||
| if ( | ||
| rows.length !== expectedCount || | ||
| rows[0]?.value !== 1 || | ||
| rows[rows.length - 1]?.value !== expectedCount | ||
| ) { | ||
| throw new Error(`Expected rows 1 through ${expectedCount}`); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.