What I learned from my first serious attempt low-level Haskell programming

Jeffrey Yasskin jyasskin at gmail.com
Thu Apr 5 10:06:28 EDT 2007


On 4/5/07, Simon Peyton-Jones <simonpj at microsoft.com> wrote:
> | 6. The inliner is a bit too greedy.  Removing the slow-path code from
> |    singleton doesn't help because popSingleton is only used once; but
> |    if I explicitly {-# NOINLINE popSingleton #-}, the code for
> |    singleton itself becomes much smaller, and inlinable (15% perf
> |    gain).  Plus the new singleton doesn't allocate memory, so I can
> |    use even MORE realWorld#s.
>
> That's a hard one!  Inlining functions that are called just once is a huge win usually. I don't know how to spot what you did in an automated way.
>

I believe gcc uses __builtin_expect()
(http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Other-Builtins.html#index-g_t_005f_005fbuiltin_005fexpect-2393)
to let the programmer say that a branch is unlikely to be taken (i.e.
is the slow path). If such a thing were available in GHC, Stefan
wouldn't even have needed to pull the slow path code from singleton;
the compiler could have done it for him.

-- 
Namasté,
Jeffrey Yasskin


More information about the Libraries mailing list