Another post on package compilation time

Package author here. As mentioned by @ericphanson, indeed the lag length is a type parameter, so every time you estimate a model with a new lag length, it is a new type and thus certain methods need to be recompiled (e.g., the likelihood). The advantage of doing this is that it allows the compiler to make certain optimizations, such as unrolling the loop in the likelihood for small values of p and q. The tradeoff is more compilation. I’ve however benchmarked this against not parameterizing the type, and the difference in compile times wasn’t actually all that large. I’m not entirely sure why that is; I think it must have to do with the fact that either way, you wind up passing a new closure into Optim.optimize for every model you’re fitting (because optimize only accepts single argument functions; see here), and that triggers some recompilation anyhow. Perhaps @pkofod can chime in here.

5 Likes