Library-vs-local performance

Don Stewart dons at
Tue Jun 24 15:56:15 EDT 2008

> sedillard:
> >    Hi,
> > 
> >    I've got a library that I'm in the process of uploading to hackage
> >    (waiting for account) but the darcs repo is here:
> > 
> >    [1]
> > 
> >    I notice a slight drop in performance when I install the library using
> >    cabal. Maybe 10-20%, on one particular function. This is in comparison to
> >    when the library is 'local', as in, the source files are in the same
> >    directory as the client application.
> Lack of unfolding and inlining when compiled in a package? Try compiling
> with -O2, for maximum unfolding.
> >    What could be causing the performance drop? The function in question
> >    requires impractical amounts of inlining (This is something of an
> >    experiment), but I don't see how installing it as a library affects that.
> >    The functions to be inlined are small, surely available in the .hi files.
> You can check this via -show-iface
> >    Its only when they are applied do they agglomerate into a big mess -
> >    80-200K lines of core.
> > 
> >    The function in question is invertMany in examples/Examples.hs.

Some general remarks, GHC isn't (yet) a whole program compiler by
default. So it doesn't, by default, inling entire packages across
package boundaries. So you can lose some specialisation/inlining,
sometimes, by breaking things across module boundaries.

That said, it's entirely possible to program libraries in a way to
specifically allow full inlining of the libraries. The Data.Binary and
Data.Array.Vector libraries are written in this style for example,
which means lots of {-# INLINE #-} pragmas, maximum unfolding and high
optimisation levels.

-- Don

More information about the Glasgow-haskell-users mailing list