Repository navigation
feat: expose lazy rows on managed SQLite queries - #541
chrispader wants to merge 5 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
chrispader
left a comment
There was a problem hiding this comment.
Note
Chris's AI partner in code reporting in (Claude Opus 5.5). 🤖
The code is consistent, but it shouldn't close #398 yet: the benchmark doesn't show a benefit, and the docs are incomplete. I reviewed this PR and Callstack's Apex model reviewed it separately. Neither of us found a code bug. The managed lazy paths go through the same queue, pending-async tracking and error normalization as executeAsync. Prepared statements wrap errors the same way, and the Node mock matches native.
- "Fixes #398" isn't backed by numbers yet. The issue asks to compare first-row latency, partial and full reads, and peak native and JS memory on Release devices. These cases measure latency only, and neither PR body reports results. Post the Release results with memory, or change the link to "Part of #398". (Claude, inline)
- The memory figures depend on GC timing.
run()dropsrowsbut never forces a collection, and the runner calls it 11 times back to back. So each lazy run's ~100k unconverted rows can stay registered as external memory, andpeakBytesforread-lazy-firstandread-lazy-partialcan include earlier runs. Add a reset that yields or collects between runs, or say that these peaks depend on GC timing. (Apex, inline) - The guides that list the query methods leave out the lazy ones.
transactions.mdx(lines 32, 42 and 60) andprepared-statements.mdx:6still list four query methods. The pending-async rule attransactions.mdx:60leaves outtx.executeLazyAsync(), even thoughtx.commit()throws while one is pending.transaction.ts:48andmock/transaction.ts:20still tell users to "Await all tx.executeAsync calls first". (Apex) - The shape of lazy rows is undocumented.
rowsonly haslength,item()andtoArray().for…ofand spreading fail with "rows is not iterable".JSON.stringify(result)silently writes{"rows":{"length":100000}}, where the eager result serialized fully. TypeScript catches iteration, but not the JSON case or code ported from therows._arrayexample 20 lines above. One sentence in the new section would cover it. (Apex, inline) - Adding required interface members is a type-level break. The new methods are required on
NitroSQLiteConnection,TransactionandPreparedStatement, so user test doubles typed as those interfaces stop compiling on a minor release. Please mention it in the release announcement. Also,docs/scripts/check-api.mjsdoesn't pinexecuteLazy,executeLazyAsync,LazyQueryResultorLazyQueryRows. (Apex)
The device spec, executeLazy.spec.ts, hasn't run on this draft: only Fast checks ran.
| @@ -102,6 +103,14 @@ export const readCases: BenchmarkCase[] = [ | |||
| label: '10k narrow rows · raw arrays read + access', | |||
| setup: setupNarrowRawRead, | |||
| }, | |||
| ...(['first', 'partial', 'full'] as const).flatMap((access) => | |||
| rowCount = rows.length | ||
| if (access === 'full') { | ||
| const all = '_array' in rows ? rows._array : rows.toArray() | ||
| assertBenchmark( |
There was a problem hiding this comment.
Apex: Nothing collects between the 11 back-to-back runs, so unconverted lazy rows from earlier runs can still count as external memory when peakBytes is sampled. Yield or collect between runs, or note that the first-row and partial peaks depend on GC timing.
|
|
||
| ```ts | ||
| const { rows } = await db.executeLazyAsync<{ id: number; name: string }>( | ||
| 'SELECT id, name FROM people WHERE age >= ? ORDER BY id', |
There was a problem hiding this comment.
Apex: Please say that lazy rows only offer length, item() and toArray(): no index access, no iteration, and no _array, and that JSON.stringify(result) doesn't include the rows. The eager example just above uses rows._array, so readers will try the same here.
| @@ -66,6 +70,10 @@ export interface NitroSQLiteConnection { | |||
| execute: ExecuteQuery | |||
| /** Queue one SQL statement and resolve with its result. */ | |||
| executeAsync: ExecuteAsyncQuery | |||
| /** Execute one statement synchronously with on-demand row conversion. Throws while the connection is busy. */ | |||
| executeLazy: ExecuteLazyQuery | |||
There was a problem hiding this comment.
Apex (low): Making these members required breaks user code that implements NitroSQLiteConnection, Transaction or PreparedStatement, such as test doubles. That's fine for this feature, but worth naming in the release announcement.
029ac43 to
03d4e8f
Compare
5fd9acb to
d38e1da
Compare
d38e1da to
86284fc
Compare
86284fc to
bcbae2b
Compare
cfed2c1 to
6ae1b09
Compare
e8961d0 to
f48b1f1
Compare
f48b1f1 to
48201ae
Compare
48201ae to
a97f6bf
Compare
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
a97f6bf to
212aac0
Compare
When a screen reads only a few rows from a large result, the managed eager API still converts every row. Use
executeLazyorexecuteLazyAsyncto get cached rows on demand throughrows.item(index)and convert the entire result withrows.toArray(). These methods follow the managed connection and transaction queues and work with prepared statements.Builds on #537.
Part of #398
Reviewed with sol-loop: 2 rounds with gpt-6.2-sol on high. Sol verdict: approved.
Note
🤖 Generated with Codex