[Haskell-cafe] cost of modules

Simon Peyton-Jones simonpj at microsoft.com
Wed Mar 28 12:06:52 EDT 2007


| I believe you are seeing a speed decrease, because GHC is not inlining
| functions as much when you split them into modules. If you add
| explicit inline statements, I think you should be able to get back to
| your original timings.

Generally speaking GHC will inline *across* modules just as much as it does *within* modules, with a single large exception.

If GHC sees that a function 'f' is called just once, it inlines it regardless of how big 'f' is.  But once 'f' is exported, GHC can never see that it's called exactly once, even if that later turns out to be the case.  This inline-once optimisation is pretty important in practice.

So: do not export functions that are not used outside the module (i.e. use an explicit export list, and keep it as small as possible).

Simon



More information about the Haskell-Cafe mailing list