Description
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 ofOwned
,GpuOnly
, andRemoteImage
.- 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:
How to reproduce
- Clone the project: https://github.com/luna/ide/tree/wip/wd/rust-bug-68324
- Run
./scripts/watch.sh
- it will compile it and report the time. - 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). - Observe the time.
The generation of structs / impls is done in:
lib/core/src/system/gpu/data/texture.rs
line 326lib/core/src/system/gpu/data/uniform.rs
line 269lib/core/src/system/gpu/data/uniform.rs
line 272lib/core/src/system/gpu/data/uniform.rs
line 290