Repository navigation
feat: convert native SQLite result rows on demand - #537
chrispader wants to merge 10 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 collaborator dropping in (Claude Opus 5.5). 🤖
The native design is sound, but no CI job has built or run the new code, and one line breaks the declared Nitro range. I reviewed this PR and Callstack's Apex model reviewed it separately. Apex compiled the changed translation units with clang++ -fsyntax-only against react-native-nitro-modules@0.37.2 and React Native's jsi.h, and they came back clean.
What we both checked:
-
Lifetime: rows are deep copies, so they outlive the statement and connection. Native code holds no strong JS references.
-
Re-entrancy: a row that is mid-conversion is swapped out and restored if conversion throws.
-
Bounds: NaN, ±∞, fractions, negative and out-of-range indices are rejected.
-
Value parity: both paths share
convertQueryRow. Int64 arrives as a double, BLOBs are copied, and NULL isnull. -
Threading: conversion only happens on the JS thread and holds no connection mutex.
-
Eager path: the refactor behaves the same as before.
-
Neither CI nor the C++ tests have built this code.
executeLazy.spec.tsis the only test that reaches it, because the Jest mocks stub the lazy methods. It runs only in the iOS, Android and macOS harness jobs, which skip drafts.scripts/test-cpp.shdoesn't compileNitroSQLiteOperations.cppor the new file either, so even a compile error would merge green. Please run the harness, by marking the PR ready or with a fullworkflow_dispatch. A host C++ test for the row storage would help too. (both) -
ArrayBuffer::getExternalMemorySize()breaks the declared Nitro range. It first appears inreact-native-nitro-modules0.37.1, while the peer range is>=0.35.0. Every BLOB here is an owning copy, so(*blob)->size()gives the same number on every version. The alternative is raising the peer floor. (Claude, inline) -
The cache and accessors are looked up through the prototype chain.
hasProperty(runtime, "cache")is true for an inheritedcache. IfObject.prototype.cacheexists, twoitem(0)calls return different objects, and the second throws "Cannot access a SQLite row while it is being converted".setPropertywould also call an inherited setter. The same applies toitemandtoArray. Since this file already guards against prototype pollution, checking own properties and defining them withObject.definePropertywould be consistent. (Apex, inline) -
Small items (Claude, inline):
item(i)rebuilds aPropNameIDfor every column on every unconverted row. The eager path builds them once per result, so reading rows one at a time can end up slower than eager.- Once every row is converted,
_data.rowsstill holds N empty vectors until GC: about 24 MB per 1M rows.
Apex also noted, as hardening only, that getNativeState is dereferenced unchecked at lines 68 and 74. Nitro's null checks only exist in debug builds, so a null state would crash a release build. JS can't reach the owner today.
| if (const auto* text = std::get_if<std::string>(&*value)) { | ||
| bytes += stringAllocationSize(*text); | ||
| } else if (const auto* blob = std::get_if<std::shared_ptr<ArrayBuffer>>(&*value)) { | ||
| bytes += (*blob)->getExternalMemorySize(); |
There was a problem hiding this comment.
Claude (medium): getExternalMemorySize() was added to ArrayBuffer in react-native-nitro-modules 0.37.1, and the peer range still allows >=0.35.0. Apps on 0.35.x–0.37.0 would fail to compile. These BLOBs are owning copies, so (*blob)->size() gives the same result on every version.
|
|
||
| jsi::Object SQLiteLazyQueryRows::toRows(jsi::Runtime& runtime) { | ||
| auto owner = toObject(runtime).asObject(runtime); | ||
| if (!owner.hasProperty(runtime, "cache")) { |
There was a problem hiding this comment.
Apex (low): hasProperty also sees an inherited Object.prototype.cache, so no own cache gets created, and item(0) read twice stops returning the same object. setProperty on line 57 is a JS [[Set]], so an inherited setter would swallow the cache. Checking own properties and installing with Object.defineProperty would close this, matching the Object.create(null) guard right below. The same applies to item and toArray at lines 63–75.
|
|
||
| std::vector<jsi::PropNameID> itemNames; | ||
| if (names == nullptr) { | ||
| itemNames = makeQueryColumnNames(runtime, _data.columnNames); |
There was a problem hiding this comment.
Claude (low): Each unconverted item() call builds a PropNameID for every column. toArray() and the eager converter build them once per result. A list that reads 5k rows through item(i) creates 5k × columns of them. Caching the PropNameIDs per result would close the gap.
029ac43 to
03d4e8f
Compare
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Compile lazy conversion on draft CI against Nitro 0.35.0 and the installed version. Keep row count stable after releasing positional storage. Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Leave Operations to native application jobs because its filesystem wrapper does not compile on Linux hosts. Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
cfed2c1 to
6ae1b09
Compare
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Large queries can spend time building JavaScript row objects that callers never read. The native
executeLazyandexecuteLazyAsyncmethods retain the completed result in positional storage and convert each row on first access. Repeated reads return the same row object, and Nitro tracks the native allocation while unconverted rows remain.Part of #398.
Reviewed with sol-loop: 2 rounds with gpt-6.2-sol on high. Sol verdict: approved.
Note
🤖 Generated with Codex