Skip to content

perf: flag the last column of each name once per result - #628

Open
chrispader wants to merge 1 commit into
mainfrom
perf/result-last-column-flags
Open

chrispader wants to merge 1 commit into
mainfrom
perf/result-last-column-flags

Conversation

@chrispader

@chrispader chrispader commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

When an asynchronous query result switches to JSON, each BLOB, non-finite number or malformed UTF-8 cell is patched in afterwards. Before patching, the builder scanned every later column name to check whether a column with the same name would overwrite the cell. That makes wide results quadratic in the column count: 256 rows with 2,000 BLOB columns do about 512 million name comparisons.

The builder now records once per result, next to the JSON keys, whether each column is the last one with its name, and appendPatch() reads that flag. The last column still wins, including over an earlier BLOB, which a new host test covers. On an M5 Pro, building that 2,000-column BLOB result drops from a median of 955 ms to 28 ms.

🤖 Generated with Claude Code

Summary by CodeRabbit

Bug Fixes

  • Fixed JSON-converted query results with duplicate column aliases. Aliases now retain their original position while showing the value from the last matching column, including in batches containing BLOB data. This keeps the output consistent when multiple query columns use the same name.

@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
react-native-nitro-sqlite Skipped Skipped Dec 2, 2026 9:45pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The query result builder tracks the last occurrence of each column name when creating JSON output. Patch recording uses this metadata, and a test checks duplicate aliases across a batch.

Changes: JSON duplicate column handling

Layer / File(s) Summary
Track and apply last-occurrence metadata
packages/nitro-sqlite-core/cpp/SQLiteQueryResults.hpp, packages/nitro-sqlite-core/cpp/SQLiteQueryResults.cpp, packages/react-native-nitro-sqlite/tests/cpp/queryResults.test.cpp
The builder records which column occurrence is last for each name and uses that flag when adding JSON patches. A test covers a duplicate alias where a later numeric value replaces an earlier BLOB value while retaining the alias position.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Merge Risk: Minimal · up to bd950

This is a performance optimization for building JSON query results with duplicate column names. Results should be unchanged, and the new test covers the duplicate-alias case. No merge-blocking risk is apparent.

Security architecture risk: Minimal · up to bd950

React Native Nitro SQLite still returns the last value for a duplicate column alias. The change makes that rule cheaper to enforce during JSON conversion without changing who can run queries or what their results contain.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "perf: flag the last column of each name once per result" matches the main change. The builder in SQLiteQueryResults.cpp and SQLiteQueryResults.hpp now records once per result whether each c…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "perf: flag the last column of each name once per result" matches the main change. The builder in SQLiteQueryResults.cpp and SQLiteQueryResults.hpp now records once per result whether each column is the last one with its name, and appendPatch() reads that flag instead of scanning later column names. The added test covers the duplicate-alias BLOB case. The title names the optimization and its scope, and it is specific enough for a teammate scanning history to understand the primary change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ef4fdf1 and bd950c9.

Files selected for processing: 2

  • packages/nitro-sqlite-core/cpp/SQLiteQueryResults.cpp
  • packages/nitro-sqlite-core/cpp/SQLiteQueryResults.hpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

When an asynchronous result switched to JSON, every BLOB, non-finite number or
malformed UTF-8 cell scanned the remaining column names to check whether a
later column with the same name would overwrite it. A result with 256 rows and
2,000 BLOB columns made about 512 million name comparisons.

The builder now records, once per result and next to the JSON keys, whether
each column is the last one with its name. The last column still wins,
including when an earlier column holds a BLOB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Codex <noreply@openai.com>
@chrispader
chrispader force-pushed the perf/result-last-column-flags branch from ef4fdf1 to bd950c9 Compare December 2, 2026 21:45

This branch was previously deployed

1 inactive deployment
Preview — bd950c9f Deployed Dec 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant