perf(#664): bypass Arrow for asyncpg record COPY - #666
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #666 +/- ##
==========================================
+ Coverage 77.22% 77.27% +0.05%
==========================================
Files 475 475
Lines 67824 67892 +68
Branches 9322 9335 +13
==========================================
+ Hits 52374 52463 +89
+ Misses 12042 12038 -4
+ Partials 3408 3391 -17
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
AsyncpgDriver.load_from_records()executemany()crossover benchmarkRoot cause
The generic
load_from_records()implementation materialized every in-memory batch as a PyArrow table. AsyncPG's native Arrow ingest implementation then converted that table back into Python row tuples before callingcopy_records_to_table(). The redundant conversion imposed fixed overhead that dominated small and medium record batches.Behavior
Direct AsyncPG record loads now preserve explicit column order or the first mapping's key order, validate the full batch before truncating or copying, and retain native JSON/JSONB mappings, arrays, UUIDs, and nulls. Empty batches, mixed row shapes, inconsistent mapping keys, missing positional columns, and row-width mismatches fail before database I/O.
Record batches execute exactly one
copy_records_to_table()call. Returned jobs report the original destination,format="records", exactrows_processed, andbytes_processed=0. The inherited CockroachDB driver uses the same implementation without changing its advertised capabilities.Benchmark
The conditional real-PostgreSQL benchmark uses one session and table, three warmups, truncation outside timed sections, and 15 timed samples per variant. Median results from the local PostgreSQL service were:
executemany()Closes #664