[Haskell-cafe] cost of modules

Tim Chevalier catamorphism at gmail.com
Tue Mar 27 18:04:37 EDT 2007

On 3/27/07, Jeremy Shaw <jeremy.shaw at linspireinc.com> wrote:
> At Tue, 27 Mar 2007 23:10:21 +0200,
> Fawzi Mohamed wrote:
> > If someone has an idea on how else I can improve timings please tell me.
> 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.

It could be inlining or it could be other optimizations. From the data
the OP gives, I don't think it's possible to conclude which ones.

> Below is an example of how to add INLINE statements.
> someFunction :: (Word8 -> Maybe Word8 -> Bool) -> B.ByteString -> B.ByteString
> someFunction = ...
> {-# INLINE someFunction #-}
> I am not sure what the downsides are. It probably makes the resulting
> binary bigger, and takes longer to compile. Though, probably not any
> worse than if you just put everything in one module?

That's not necessarily so; what if you end up adding an INLINE pragma
for a function with several call sites that GHC wouldn't have inlined
at all in the original single-module program?

> It might be the case that you only need to INLINE one or two functions
> to get most of the speed back.

Yes, which is why it's a good idea to do profiling before sprinkling
INLINE pragmas wantonly around your code.


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