[Haskell-cafe] cost of modules

Tim Chevalier catamorphism at gmail.com
Tue Mar 27 17:19:31 EDT 2007

On 3/27/07, Fawzi Mohamed <fmohamed at mac.com> wrote:
> I decided to cleanup my program by splitting it in different modules.
> As I was curious about
> the cost of splitting it, or dually the efficiency of the intermodule
> optimization I timed it before and after the split.
> These are the results (ghc-6.6.20070129 on Linux AMD64):
> Original: 3 Modules with the computational one with an export list
> real    0m0.385s
> user    0m0.378s
> sys     0m0.003s
> time:100%
> Variant 1: split computational module in 6 submodules without export
> list, kept computational module reexporting the stuff with an export list
> real    0m0.467s
> user    0m0.464s
> sys     0m0.003s
> time: 122%
> Variant 2: like Variant 1 but removing the old computational module (no
> reexport list) 134%
> real    0m0.513s
> user    0m0.506s
> sys     0m0.003s
> All the functions in my modules have type specialized signatures, so
> non-specialization should almost never be an issue.
> The module with the Main function was not the exported one.
> So 20% speed hit, I had hoped for 0, but it is not unbearable (even if
> my code has to be as fast as possible, this was a very short run),
> probably I will keep it split to have cleaner code.
> Not I will have to write an export list for each module a see it the
> things improve, and how much.
> If someone has an idea on how else I can improve timings please tell me.

For starters, I'd question whether those results are statistically
significant; your program doesn't run for very long. 20% of less than
.5 seconds is short enough that the 20% hit you're seeing could be
affected by random noise. If there's a way to adjust the input to your
program so that it runs for more than a few seconds, you may want to
see what results you get that way.

Even so, intuitively I'd also expect to see a performance hit when
splitting a program into multiple modules, as GHC's optimizer is
designed with separate compilation as a consideration. As always, you
probably need to do profiling in order to figure whether it's worth
bothering about.


Tim Chevalier * chevalier at alum.wellesley.edu * Often in error, never in doubt
Confused? See http://catamorphism.org/transition.html

More information about the Haskell-Cafe mailing list