August 30th, 2024

Doctests – How were they improved?

Rust's documentation generator, rustdoc, has improved doctest efficiency by merging compatible tests, significantly reducing compilation times and enhancing error handling, with future updates expected for binary crate functionality.

Read original articleLink Icon
Doctests – How were they improved?

Rust's documentation generator, rustdoc, has undergone significant improvements to enhance the efficiency of doctests, which are code examples embedded in documentation that are automatically tested. Previously, each doctest was compiled individually, leading to excessive compilation times—over 775 seconds for libcore, with only 15 seconds spent on actual runtime. The recent changes allow for the merging of compatible doctests, reducing the number of compilations needed. Doctests are grouped by edition and other attributes, and if they cannot be merged due to specific reasons (like syntax errors or crate-level attributes), they are still compiled individually. This new approach has drastically cut down the compile time for various crates, with some examples showing reductions from several minutes to mere seconds. Additionally, the handling of corner cases has been improved, ensuring that if a merged doctest fails to compile, the system can revert to compiling them individually to identify the specific failure. Future enhancements are anticipated, including the potential for binary crates to utilize doctests more effectively.

- Rust's doctests have been optimized to reduce compilation time significantly.

- Merging compatible doctests minimizes the number of compilations required.

- The new system allows for better handling of corner cases and errors.

- Performance improvements have been demonstrated across various crates.

- Future updates may enhance the functionality of doctests in binary crates.

Link Icon 0 comments