about summary refs log tree commit diff
path: root/src/librustdoc/clean/inline.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-03-27 15:22:17 +0000
committerbors <bors@rust-lang.org>2025-03-27 15:22:17 +0000
commit217693a1f02ca6431a434926ff3417bdb6dbac2e (patch)
tree8647d21dd1a79f83aae4382fa567fc006de1af8c /src/librustdoc/clean/inline.rs
parentecb170afc878648c3ae355dbd596c8e4b6f7ebdc (diff)
parentffee55c18c19c551d58a6d68e1b3feb7618d0455 (diff)
downloadrust-217693a1f02ca6431a434926ff3417bdb6dbac2e.tar.gz
rust-217693a1f02ca6431a434926ff3417bdb6dbac2e.zip
Auto merge of #138927 - nnethercote:rearrange-Item-ItemInner, r=GuillaumeGomez
rustdoc: Rearrange `Item`/`ItemInner`.

The `Item` struct is 48 bytes and contains a `Box<ItemInner>`;
`ItemInner` is 104 bytes. This is an odd arrangement. Normally you'd
have one of the following.

- A single large struct, which avoids the allocation for the `Box`, but
  can result in lots of wasted space in unused parts of a container like
  `Vec<Item>`, `HashSet<Item>`, etc.

- Or, something like `struct Item(Box<ItemInner>)`, which requires the
  `Box` allocation but gives a very small Item size, which is good for
  containers like `Vec<Item>`.

`Item`/`ItemInner` currently gets the worst of both worlds: it always
requires a `Box`, but `Item` is also pretty big and so wastes space in
containers. It would make sense to push it in one direction or the
other. #138916 showed that the first option is a regression for rustdoc,
so this commit does the second option, which improves speed and reduces
memory usage.

r? `@GuillaumeGomez`
Diffstat (limited to 'src/librustdoc/clean/inline.rs')
-rw-r--r--src/librustdoc/clean/inline.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs
index 4fd669ab6d1..e0e09b53fc2 100644
--- a/src/librustdoc/clean/inline.rs
+++ b/src/librustdoc/clean/inline.rs
@@ -151,7 +151,7 @@ pub(crate) fn try_inline(
     let mut item =
         crate::clean::generate_item_with_correct_attrs(cx, kind, did, name, import_def_id, None);
     // The visibility needs to reflect the one from the reexport and not from the "source" DefId.
-    item.inline_stmt_id = import_def_id;
+    item.inner.inline_stmt_id = import_def_id;
     ret.push(item);
     Some(ret)
 }
@@ -655,11 +655,11 @@ fn build_module_items(
                 // Primitive types can't be inlined so generate an import instead.
                 let prim_ty = clean::PrimitiveType::from(p);
                 items.push(clean::Item {
-                    name: None,
-                    // We can use the item's `DefId` directly since the only information ever used
-                    // from it is `DefId.krate`.
-                    item_id: ItemId::DefId(did),
                     inner: Box::new(clean::ItemInner {
+                        name: None,
+                        // We can use the item's `DefId` directly since the only information ever
+                        // used from it is `DefId.krate`.
+                        item_id: ItemId::DefId(did),
                         attrs: Default::default(),
                         stability: None,
                         kind: clean::ImportItem(clean::Import::new_simple(
@@ -679,9 +679,9 @@ fn build_module_items(
                             },
                             true,
                         )),
+                        cfg: None,
+                        inline_stmt_id: None,
                     }),
-                    cfg: None,
-                    inline_stmt_id: None,
                 });
             } else if let Some(i) = try_inline(cx, res, item.ident.name, attrs, visited) {
                 items.extend(i)