Skip to content

Macro expansion is quadratic in the number of let statements. #10607

Closed
@huonw

Description

@huonw

The following (bash) shell snippet prints let _x: int; /* <number> */ 5000 times, which makes the compiler very unhappy.

$ echo 'fn main() { ' 'let _x: int; /*'{1..5000}'*/' '}'  |  rustc - -Z time-passes
time: 0.056 s   parsing
time: 0.001 s   gated feature checking
time: 0.002 s   std macros injection
time: 0.010 s   configuration 1
time: 9.157 s   expansion
[...]

(the total time is 10.3s.)

First few lines of perf report:

    32.15%     rustc  libsyntax-2bb2d559d93ae8f0-0.9-pre.so  [.] hash::Writer$SipState::write::hadb05778635375a2fhaT::v0.9$x2dpre
    22.41%     rustc  libsyntax-2bb2d559d93ae8f0-0.9-pre.so  [.] hashmap::HashMap::bucket_for_key_with_hash::h5b953adb9726637Rjab::v0.9$x2dpre
     9.02%     rustc  libsyntax-2bb2d559d93ae8f0-0.9-pre.so  [.] hash::Streaming$SipState::result_u64::h1e5a7083bc4c3f6bAga7::v0.9$x2dpre
     8.46%     rustc  libsyntax-2bb2d559d93ae8f0-0.9-pre.so  [.] hash::Hash$A::hash_keyed::h463e3d8e059f531Zha5::v0.9$x2dpre
     4.20%     rustc  libsyntax-2bb2d559d93ae8f0-0.9-pre.so  [.] ast_util::get_sctable::he0d4d721b1287a6aH::v0.9$x2dpre
     3.08%     rustc  libsyntax-2bb2d559d93ae8f0-0.9-pre.so  [.] hashmap::Map$HashMap::find::hf199eda9a92cb3f3CAa3::v0.9$x2dpre
     1.72%     rustc  libsyntax-2bb2d559d93ae8f0-0.9-pre.so  [.] tuple::inner::Eq$__extensions__::eq::h4384d9b129d29aa7Gjas::v0.9$x2dpre            ```

i.e. ~70% of the time is spend on hashing/hashmap look-ups. (cc #10586, although that's not the full problem.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-compiletimeIssue: Problems and improvements with respect to compile times.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions