Repository navigation
net: Shrink completed_body allocation when finishing HTTP load - #47454
Merged
Merged
Conversation
The responses are cached by our http cache, so shrinking the allocation can save memory by discarding excess capacity. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
completed_body allocation when finishing HTTP load
mrobinson
approved these changes
Aug 23, 2026
yezhizhen
approved these changes
Aug 23, 2026
pull Bot
pushed a commit
to AmirulAndalib/servo
that referenced
this pull request
Sep 7, 2026
Reduce the amount of intermediate reallocations by preallocating more generously. if we don't have any information, we at least preallocate something. If the content is compressed and we know the compressed content-length, we pre-allocate 5x, which should cover typical compressions ratios. For the http-cache, the backing allocation will be shrunk once everything is received (see servo#47454). Also change the calculation in fetch.rs to prevent underflow, if we do call the trait wrongly. On typical pages this seems to avoid ~90% of the reallocs during fetching and does not seem to negatively affect memory usage. Testing: No observable change, covered by existing tests --------- Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
RichardTjokroutomo
pushed a commit
to RichardTjokroutomo/servo
that referenced
this pull request
Oct 6, 2026
…vo#47454) The responses are cached by our HTTP cache, so shrinking the allocation can save memory by discarding excess capacity. Not all responses are cached, but currently we don't have a way to determine if it is retained by the HTTP cache or not, and it's unclear if adding such a mechanic would save work compared to just always shrinking. The network loading process already contains a series of potential re-allocations (by growing the `Vec`), so adding another potential reallocation to shrink should be fine. Testing: No behavior change. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
RichardTjokroutomo
pushed a commit
to RichardTjokroutomo/servo
that referenced
this pull request
Oct 6, 2026
Reduce the amount of intermediate reallocations by preallocating more generously. if we don't have any information, we at least preallocate something. If the content is compressed and we know the compressed content-length, we pre-allocate 5x, which should cover typical compressions ratios. For the http-cache, the backing allocation will be shrunk once everything is received (see servo#47454). Also change the calculation in fetch.rs to prevent underflow, if we do call the trait wrongly. On typical pages this seems to avoid ~90% of the reallocs during fetching and does not seem to negatively affect memory usage. Testing: No observable change, covered by existing tests --------- Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
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.
The responses are cached by our HTTP cache, so shrinking the allocation can save memory by discarding excess capacity. Not all responses are cached, but currently we don't have a way to determine if it is retained by the HTTP cache or not, and it's unclear if adding such a mechanic would save work compared to just always shrinking. The network loading process already contains a series of potential re-allocations (by growing the
Vec), so adding another potential reallocation to shrink should be fine.Testing: No behavior change.