Proposal: Compiler statistics command line option


#1

There are concerns about the memory usage when running rustc in low-memory machines. Also, I myself am experiencing problems due to the compiler generated type names is exceeding the limit. However, although we can see that for example 1.5G memory was in use on peak, we don’t know how to divide them in to pieces that we can later review the code to optimize (including both the compiler itself and the source code it is compiling). And the type name space seems to be accumulative and we don’t know how to measure it from outside until we reach the limit.

This proposal is to add some command line options to rustc so it will print the statistics for a specific run.

Ideally the statistics should include but not limited to the following:

  • Compile time
  • Avg compile time / line
  • Source files in total count and lines in total
  • Crates count/name length in total, trait count/name length in total, method/fn count/name length in total, struct/enums count/name length in total. All above should be restricted to explicitly specified by user (after macro expension).
  • Compiler generated items (trait, method, struct/enums etc) counts and name length in total
  • Whenever the compiler has a hard limit set on an internal measurement, print the limit and the actual (maximum) usage. For example, the “type name” space.

We might also want this to be the default option for the playground, as it will help us to communicate on code optimizations.

We might also, if keeping those statistics live is not too expensive, allow the user to set the memory usage limit and then once it reaches the limit, exit politely with an error message, and print the statistics above.


#2
rustc -Ztime-passes
rustc -Ztime-llvm-passes
rustc -Zinput-stats

Only types:

RUST_LOG=info rustc

after the string Ty interner

Overal stats:

rustc -Zhir-stats

#3

Thanks, just want to show my command line under Windows Powershell.

& {$env:RUST_LOG='info'; rustc}