How refactoring a macro reduced my Rust project build time from 4 hours to 40sec

iceiix | 124 points

This is clearly an O(n^2) situation somewhere in LLVM. Usually it is pretty easy to fix by adding a cache or two; or by changing a linear search to a hash map.

If OP could produce an LLVM reproduction sample then this would be a good help for LLVM team.

garganzol | 4 years ago

Does anyone know what LLVM does that breaks for long functions? Is the optimization pass doing something quadratic in the number of basic blocks in the function?

adrianN | 4 years ago

I hope this is considered a compiler bug.

cespare | 4 years ago

This is generally good practice. Put runtime logic in functions, then write macros with just enough syntax sugar to bridge the gap to those functions.

MBlume | 4 years ago

TL;DR: Don't autogenerate a large monolithic function. Generate many small functions instead.

lopsidedBrain | 4 years ago

It sounds like this is an LLVM problem. So could this same thing happen in C?

Thorrez | 4 years ago