Repository navigation
perf: read a body of unknown length into one buffer of its total - #22
Closed
metalwarrior665 wants to merge 1 commit into
Closed
metalwarrior665 wants to merge 1 commit into
metalwarrior665 wants to merge 1 commit into
Conversation
A decompressed body has no length in advance, so its chunks went into a buffer that grew as they came: copied at each doubling, and the regrowth (reallocation and copying) took about 6% of the CPU of an Instagram profile run, a few hundred KB per response. The chunks are now kept and copied once into a buffer of their total. A body of known length is still read into its preallocated buffer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0148RYR4BTGyCYHENSRZjC3S
Member
Author
|
Closing: no gain measured. Paired instagram-rs runs (apify-store/instagram-rs#93, 10k profiles at 1 GB, both builds at the same time) took 50.0 and 49.4 CPU-seconds with this change against 46.6 and 48.9 without. Copying the chunks once at the end costs about as much as letting the buffer grow. Generated by Claude Code Generated by Claude Code |
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.
A decompressed body has no length in advance (
Content-Lengthis the compressed size).ResponseBody::bytesused to start with an emptyBytesMut, which grew as the chunks came, copying what it held at each doubling. On the Instagram profile scraper that regrowth (jemallocrallocxplus the copies) was about 6% of the run's CPU, at a few hundred KB per response.The chunks are now kept until the body ends and copied once into a buffer of their total. A body of known length still goes into its preallocated buffer, and a single-chunk body is still not copied.
A new test reads 200 chunks with and without a known length. The effect will be measured with instagram-rs paired runs.
Generated by Claude Code