diff options
| author | Noah Lev <camelidcamel@gmail.com> | 2022-01-10 12:24:20 -0800 |
|---|---|---|
| committer | Noah Lev <camelidcamel@gmail.com> | 2022-01-14 12:05:35 -0800 |
| commit | cef250d90bbf65af7ec3c8ff5865eaa12a5f4a21 (patch) | |
| tree | 07ddf96ae0eddba69edd12a7b4945684a076db8f | |
| parent | 8f59eb6da014cb146c1477ab0ddf35729c88e99f (diff) | |
| download | rust-cef250d90bbf65af7ec3c8ff5865eaa12a5f4a21.tar.gz rust-cef250d90bbf65af7ec3c8ff5865eaa12a5f4a21.zip | |
Make `AVG_PART_LENGTH` a power of 2
I seem to recall that in general, it's best to request an allocation with a size that's a power of 2. The low estimate of 5 was probably a little too low as well.
| -rw-r--r-- | src/librustdoc/html/url_parts_builder.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/librustdoc/html/url_parts_builder.rs b/src/librustdoc/html/url_parts_builder.rs index 26cebe8c72b..66c879b8392 100644 --- a/src/librustdoc/html/url_parts_builder.rs +++ b/src/librustdoc/html/url_parts_builder.rs @@ -105,10 +105,17 @@ impl UrlPartsBuilder { /// This is just a guess at the average length of a URL part, /// used for [`String::with_capacity`] calls in the [`FromIterator`] -/// and [`Extend`] impls. +/// and [`Extend`] impls, and for [estimating item path lengths]. /// -/// This is intentionally on the lower end to avoid overallocating. -const AVG_PART_LENGTH: usize = 5; +/// The value `8` was chosen for two main reasons: +/// +/// * It seems like a good guess for the average part length. +/// * jemalloc's size classes are all multiples of eight, +/// which means that the amount of memory it allocates will often match +/// the amount requested, avoiding wasted bytes. +/// +/// [estimating item path lengths]: estimate_item_path_byte_length +const AVG_PART_LENGTH: usize = 8; /// Estimate the number of bytes in an item's path, based on how many segments it has. /// |
