Please help! How can I speed up compile times? Still compiling after hours...

50 points fatman859

Hi, I have a program that takes more than an hour to compile. It is still compiling as of writing this post at 2 hours elapsed so far. The program has a large number of structs equal to roughly 3000 structs with 2-3 macros on each. They are structs that are intended to be used in my graphql api (using the async-graphql lib). The structs are automatically generated using a script for those wondering. How can I speed up compile times? This is the first time I have hit a compile time this bad. The structs are part of the same scope, each representing a table in my database so I would prefer not to separate them into separate crates. The recursion limit has also been set to 1024 if it matters since anything less was giving errors. Any help would be appreciated, thanks!

EDIT:

My ram usage is very high, I have 32gb ram, 12 core AMD 3600x. I have 300-400mb left and roughly 2GB of swap used. I also tried changing the linker to mold and saw no improvement in other similarly structured libs I've created so I do not think it is a linking issue.

EDIT 2:

Issue has been resolved. It was being caused by this macro: diesel::allow_tables_to_appear_in_same_query! . It was generating a very large amount of code for every single possible combination that could be created using the very large number of tables. This is automatically generated when using print-schema in diesel cli. This macro will need to specified manually for each possible relationship you want to query among your tables to avoid large amounts of code generation. Compile times dropped to 2-3mins.