cross module optimization issues

Simon Peyton-Jones simonpj at
Wed Nov 19 11:17:09 EST 2008

| I'm compiling with -O2 -Wall.  After looking at the Core output, I
| think I've found the key difference.  A function that is bound in a
| "where" statement is different between the monolithic and split
| sources.  I have no idea why, though.  I'll experiment with a few
| different things to see if I can get this resolved.

In general, splitting code across modules should not make programs less efficient -- as Don says, GHC does quite aggressive cross-module inlining.

There is one exception, though.  If a non-exported non-recursive function is called exactly once, then it is inlined *regardless of size*, because doing so does not cause code duplication.  But if it's exported and is large, then its inlining is not exposed -- and even if it were it might not be inlined, because doing so duplicates its code an unknown number of times.  You can change the threshold for (a) exposing and (b) using an inlining, with flags -funfolding-creation-threshold and -funfolding-use-threshold respectively.

If you find there's something else going on then I'm all ears.


More information about the Glasgow-haskell-users mailing list