Repository navigation
http_loader: Improve preallocation heuristic - #47455
Merged
Merged
Conversation
jschwe
force-pushed
the
net_allocations
branch
from
August 23, 2026 12:52
92a71b3 to
b735ad4
Compare
Narfinger
requested changes
Aug 24, 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, we pre-allocate 5x, which should cover typical compressions ratios. For the http-cache, the backing allocation will be shrunk once everything is received. Also change the calculation in fetch.rs to prevent underflow, if we do call the trait wrongly. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
Use saturating_mul to prevent potential overflows. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
jschwe
force-pushed
the
net_allocations
branch
from
September 7, 2026 03:31
b735ad4 to
39882bf
Compare
Narfinger
approved these changes
Sep 7, 2026
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.
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 #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