Skip to content

Commit cef250d

Browse files
committed
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.
1 parent 8f59eb6 commit cef250d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/librustdoc/html/url_parts_builder.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,17 @@ impl UrlPartsBuilder {
105105

106106
/// This is just a guess at the average length of a URL part,
107107
/// used for [`String::with_capacity`] calls in the [`FromIterator`]
108-
/// and [`Extend`] impls.
108+
/// and [`Extend`] impls, and for [estimating item path lengths].
109109
///
110-
/// This is intentionally on the lower end to avoid overallocating.
111-
const AVG_PART_LENGTH: usize = 5;
110+
/// The value `8` was chosen for two main reasons:
111+
///
112+
/// * It seems like a good guess for the average part length.
113+
/// * jemalloc's size classes are all multiples of eight,
114+
/// which means that the amount of memory it allocates will often match
115+
/// the amount requested, avoiding wasted bytes.
116+
///
117+
/// [estimating item path lengths]: estimate_item_path_byte_length
118+
const AVG_PART_LENGTH: usize = 8;
112119

113120
/// Estimate the number of bytes in an item's path, based on how many segments it has.
114121
///

0 commit comments

Comments
 (0)