-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Exponential compile time for the amount of impls. #68324
Copy link
Copy link
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcCall 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 ExampleCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcCall 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 ExampleCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
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
pub struct Texture<StorageType,InternalFormat,ElemType>.StorageTypeis one ofOwned,GpuOnly, andRemoteImage.(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):We also generate a single data type gathering all the texture types as variants:
And a bunch of conversions like
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:
How to reproduce
./scripts/watch.sh- it will compile it and report the time.lib/core/src/system/gpu/data/texture.rsuncomment 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).The generation of structs / impls is done in:
lib/core/src/system/gpu/data/texture.rsline 326lib/core/src/system/gpu/data/uniform.rsline 269lib/core/src/system/gpu/data/uniform.rsline 272lib/core/src/system/gpu/data/uniform.rsline 290