From 8b8f1e069fd6b81cdedf2d7ef80460a7a51d36ef Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Fri, 19 Nov 2021 21:41:23 -0500 Subject: [PATCH 1/2] rustdoc: Add static size assertion for DocFragment Tons of them are constructed, so the size has a big impact on max-rss. --- src/librustdoc/clean/types.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 41ebf270ba6..137660355c3 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -918,6 +918,10 @@ crate struct DocFragment { crate indent: usize, } +// `DocFragment` is used a lot. Make sure it doesn't unintentionally get bigger. +#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] +rustc_data_structures::static_assert_size!(DocFragment, 32); + #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] crate enum DocFragmentKind { /// A doc fragment created from a `///` or `//!` doc comment. From a65421651adfcd5123153a847c075b5a14465f1d Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Fri, 19 Nov 2021 21:54:43 -0500 Subject: [PATCH 2/2] rustdoc: Record aliases as Symbols --- src/librustdoc/clean/types.rs | 8 ++++---- src/librustdoc/html/render/cache.rs | 2 +- src/librustdoc/html/render/mod.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 137660355c3..ea43797b5bf 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1114,7 +1114,7 @@ impl Attributes { if self.doc_strings.is_empty() { None } else { Some(self.doc_strings.iter().collect()) } } - crate fn get_doc_aliases(&self) -> Box<[String]> { + crate fn get_doc_aliases(&self) -> Box<[Symbol]> { let mut aliases = FxHashSet::default(); for attr in self.other_attrs.lists(sym::doc).filter(|a| a.has_name(sym::alias)) { @@ -1122,16 +1122,16 @@ impl Attributes { for l in values { match l.literal().unwrap().kind { ast::LitKind::Str(s, _) => { - aliases.insert(s.as_str().to_string()); + aliases.insert(s); } _ => unreachable!(), } } } else { - aliases.insert(attr.value_str().map(|s| s.to_string()).unwrap()); + aliases.insert(attr.value_str().unwrap()); } } - aliases.into_iter().collect::>().into() + aliases.into_iter().collect::>().into() } } diff --git a/src/librustdoc/html/render/cache.rs b/src/librustdoc/html/render/cache.rs index 0286d2a4c81..9aa69d94215 100644 --- a/src/librustdoc/html/render/cache.rs +++ b/src/librustdoc/html/render/cache.rs @@ -70,7 +70,7 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt< // Set up alias indexes. for (i, item) in search_index.iter().enumerate() { for alias in &item.aliases[..] { - aliases.entry(alias.to_lowercase()).or_insert_with(Vec::new).push(i); + aliases.entry(alias.as_str().to_lowercase()).or_default().push(i); } } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index dd592de41bd..ffd09663f82 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -103,7 +103,7 @@ crate struct IndexItem { crate parent: Option, crate parent_idx: Option, crate search_type: Option, - crate aliases: Box<[String]>, + crate aliases: Box<[Symbol]>, } /// A type used for the search index.