cargo icon indicating copy to clipboard operation
cargo copied to clipboard

feat: support for rustdoc mergeable cross-crate info

Open weihanglo opened this issue 2 weeks ago • 1 comments

What does this PR try to resolve?

This is an unstable feature that we designed to fix several performance problems with the old system:

  1. You couldn't easily build crate docs in hermetic environments. This doesn't matter for Cargo, but it was one of the original reasons to implement the feature.
  2. We have to build all the doc resources in their final form at every step, instead of delaying slow parts (mostly the search index) until the end and only doing them once.
  3. It requires rustdoc to take a lock at the end. This reduces available concurrency for generating docs.

Part of

  • https://github.com/rust-lang/rust/issues/130676
  • https://github.com/rust-lang/cargo/issues/16306

How to test and review this PR?

Design decisions and questions:

  • A new intermediate build directory target/debug/docdeps/ shared between all rustdoc invocations: https://github.com/rust-lang/cargo/pull/16309#discussion_r2572066545
  • Doesn't take cargo clean into account yet: https://github.com/rust-lang/cargo/pull/16309#discussion_r2570354695
  • A new FileFlavor::DocParts is added: https://github.com/rust-lang/cargo/pull/16309#discussion_r2570353860
  • One doc-merge per target platform (and run in serial) https://github.com/rust-lang/cargo/pull/16309#discussion_r2570576487
  • A new status "Merging" is added. Example output:
       Documenting ...
       Documenting cargo v0.94.0 (/Users/frodo/cargo)
       Finished `dev` profile [unoptimized + debuginfo] target(s) in 29.68s
        Merging 300 docs for host
       Finished documentation merge in 2.74s
      Generated /Users/frodo/cargo/target/doc/cargo/index.html
    
  • Who should garbage collect unneeded crate docs under mergeable CCI mode, rustdoc or cargo? (or don't, we shouldn't do any garbage collection?) https://github.com/rust-lang/cargo/pull/16309#discussion_r2570485940

Simple benchmark

  • Tested against this PR on top of rust-lang/cargo@15fde07882a7480c3cdeb977c13099f5cd6ee324
  • rustdoc 1.93.0-nightly (1be6b13be 2025-11-26)
  • macOS Sequoia 15.7.1
  • Apple M1 Pro 2021
  • 32GB RAM; 10 cores
  • 300 crate doc merge
  • Test steps:
    argo check
    argo doc
    argo clean --doc && rm -rf target/debug/doc-parts/
    argo doc -Zrustdoc-mergeable-info
    argo clean --doc && rm -rf target/debug/doc-parts/
    

With -Zrustdoc-mergeable-info:

  • <40s: ~30s documenting time + 3-5s merge time
  • 76262 files, 970.5MiB total

Without -Zrustdoc-mergeable-info:

  • ~500s: 8m10s - 8m30s
  • 75242 files, 932.8MiB total

weihanglo avatar Nov 28 '25 03:11 weihanglo