Skip to content

perf(postgrest): stop wrapping every inserted and upserted row in a cast view - #2058

Merged
spydon merged 3 commits into
mainfrom
lukasklingsbo/sdk-2402-perfpostgrest-stop-wrapping-every-inserted-and-upserted-row
Oct 26, 2026
Merged

spydon merged 3 commits into
mainfrom
lukasklingsbo/sdk-2402-perfpostgrest-stop-wrapping-every-inserted-and-upserted-row

Conversation

@spydon

@spydon spydon commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2057.

Fixes SDK-2402.

Summary

_jsonRow, which insert() and upsert() (and the typed insertAll/upsertAll) use to turn each row of a list into a JSON object, ended with json.cast(). Map.cast always returns a wrapping view, even when the row already is a Map<String, dynamic>, so the key check, the columns collection, jsonEncode and the copy of the body to the encoding isolate all went through a type-checking view.

Rows that already are a Map<String, dynamic> are now returned as they are. Other maps with only String keys are copied once with Map.from. A row with a non-String key still throws ArgumentError.

Measured with a canned HTTP transport, AOT compiled, on macOS arm64:

Insert, v3 default codec Before After
10000 rows, total 10.78 ms 8.25 ms
10000 rows, longest main isolate stall 5.42 ms 2.59 ms
1000 rows, total 834 µs 776 µs

Tests

insert() and upsert() of a list holding a Map<dynamic, dynamic> and a Map<String, Object?> send the right body and columns parameter, and a row with a non-String key throws.

Summary by CodeRabbit

  • Bug Fixes
    • Insert and upsert requests now correctly serialize rows provided as maps with string keys, including maps using different value types.
    • Request columns are correctly included based on the row keys.
    • Rows with non-string keys continue to be rejected with an ArgumentError.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 776b9f5 and f0171b0.

Files selected for processing: 2
  • packages/postgrest/lib/src/postgrest_query_builder.dart
  • packages/postgrest/test/insert_builder_test.dart

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

Walkthrough

The PR changes _jsonRow to return already-typed maps directly and copy other maps with string keys. Tests cover serialization and invalid keys for insert() and upsert().

Changes: PostgREST Row Map Handling

Layer / File(s) Summary
Row normalization and mutation tests
packages/postgrest/lib/src/postgrest_query_builder.dart, packages/postgrest/test/insert_builder_test.dart
_jsonRow returns existing Map<String, dynamic> values directly and copies other maps with string keys. Tests check serialized request bodies, the columns parameter, and ArgumentError for non-String keys in insert() and upsert().

Priority: Low

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

Change: Refactor

Possibly related PRs

Suggested reviewers: androidpoet

Merge Risk: Minimal · up to f0171

No actionable issue is established; the change is mergeable after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main performance change: avoiding unnecessary cast views for inserted and upserted rows.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
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: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (2 skipped: 2 unsupported.)

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the postgrest This issue or pull request is related to postgrest label Oct 26, 2026
Base automatically changed from lukasklingsbo/sdk-2401-perfpostgrestyet_another_json_isolate-encode-request-bodies to main October 26, 2026 13:25
@spydon
spydon merged commit a05c51b into main Oct 26, 2026
47 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-2402-perfpostgrest-stop-wrapping-every-inserted-and-upserted-row branch October 26, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

postgrest This issue or pull request is related to postgrest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant