perf: serialize dataset push payloads once per chunk - #1081
Open
vdusek wants to merge 2 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1081 +/- ##
==========================================
+ Coverage 91.83% 91.97% +0.13%
==========================================
Files 51 51
Lines 3235 3229 -6
==========================================
- Hits 2971 2970 -1
+ Misses 264 259 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
vdusek
marked this pull request as ready for review
August 4, 2026 13:15
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.
Pushing to a dataset serialized every item in its own
asyncio.to_threadhop (through Crawlee'sjson_dumps), so a push paid one thread round-trip per item. That helper also pretty-prints withindent=2, and each payload was UTF-8 encoded twice — once for the per-item size check, once again while chunking._check_and_serializeand_chunk_by_sizeare replaced by a single blocking_serialize_chunk(items, offset)that fills one size-bounded JSON array and returns the next offset.push_datadrives it with oneasyncio.to_threadper chunk and pushes each chunk before serializing the next, so payloads are still streamed rather than all materialized up front.Serialization is now local and compact (
json.dumps(..., separators=(',', ':'))) rather than Crawlee'sjson_dumps, whoseindent=2is deliberate for the on-disk files people actually read. Nothing reads the wire format. Dropping the indent also lets CPython take the C encoder fast path, which it only does whenindent is None.Measured on 20k realistic items against a mocked API client:
The payload saving is shape-dependent — larger for small or deeply nested items — and compounds with the brotli work in #1052.
Two spurious API calls disappear as a side effect: the old chunker emitted an empty
[]chunk whenever the first item of a chunk landed within 2 bytes of the limit, and it pushed[]rather than nothing when PPE charging drove the push limit down to 0.Stored items are unaffected. The only observable difference is that raw request bodies are no longer pretty-printed.
✍️ Drafted by Claude Code