How to optimize compile-times (general tips)? #396
-
I just started writing a new parser recently (https://github.com/Philipp-M/express-parser), and it's still relatively simple, but it already takes ages to compile (I guess the type-system solver is going crazy?). A simple addition and the compilation jumped from 40 seconds to 4 minutes (on an AMD zen 3950x with 16 cores), I guess if I'm continuing that way, I will soon land at the hour mark ^^. Are there general tips on how to optimize compile times? My guess is, that all the anonymous closure/parser chaining creates a huge generic types, which makes things slow (in the parser above, mostly in |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I would suggest adding (The most common cause of slowdown is that rustc doesn't memoize trait solving, so it does all the work of proving |
Beta Was this translation helpful? Give feedback.
I would suggest adding
boxed
at the end of some large parsers, particularly those that involve multipleor
calls (after atom, maybe some of the earlier bindings). Due to allocation occurring at parser build time, not at run time, boxing parsers is very cheap, and can even result in speedups in some situations.(The most common cause of slowdown is that rustc doesn't memoize trait solving, so it does all the work of proving
Parser
holds for every instance every time, andor
is the most obvious location for this because it can double the chain length each call)