Skip to content

Exponential compile time for the amount of impls. #68324

Closed
@wdanilo

Description

@wdanilo

Summary

Hi! After generating over 200 impls with macros, my project build time just grew from a few seconds to 3 hours. Even worse, the compilation time grows exponentially in relation to the number of impls, so I'm reporting a bug. I do not have minimal repro, but I have an open-source code and a simple reproducible recipe.

Description

  • There is pub struct Texture<StorageType,InternalFormat,ElemType>.
  • StorageType is one of Owned, GpuOnly, and RemoteImage.
  • Combination (InternalFormat, ElemType) is approx 70 possibilities.

Then we generate the following impls (if an impl mentions 2 types, then we generate it for each combination), where (S,I,T) stands for (StorageType,InternalFormat,ElemType):

impl InternalFormat for I {...}
impl TextureElement<T> for I {...}

We also generate a single data type gathering all the texture types as variants:

pub enum AnyTextureUniform {
            $( S_I_T(Uniform<Texture<S,I,T>) ),*
}

And a bunch of conversions like

impl From<Uniform<Texture<S, I, T>>> for AnyUniform {...}

Basically, we can assume that for EVERY TEXTURE TYPE WE GENERATE 3 VARIANTS AND APPROXIMATELY 18 IMPLS.

And now the not-fun part. For 8 texture types, it compiles 42s. For 16 types - 1.5 mins. For 32 types - 10 mins. We've got 70 texture types - it takes hours.

Analysis

It seems we've got exponential growth here. Here is a detailed statistics:

image

How to reproduce

  1. Clone the project: https://github.com/luna/ide/tree/wip/wd/rust-bug-68324
  2. Run ./scripts/watch.sh - it will compile it and report the time.
  3. In the file lib/core/src/system/gpu/data/texture.rs uncomment some lines between 265 and 323. (Each line contains an array of types on the far right - the number of elements is the number of additional texture types we uncomment).
  4. Observe the time.

The generation of structs / impls is done in:

  • lib/core/src/system/gpu/data/texture.rs line 326
  • lib/core/src/system/gpu/data/uniform.rs line 269
  • lib/core/src/system/gpu/data/uniform.rs line 272
  • lib/core/src/system/gpu/data/uniform.rs line 290

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcE-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-compiletimeIssue: Problems and improvements with respect to compile times.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions