Summary of containers patches

Simon Peyton-Jones simonpj at
Fri Sep 24 04:43:49 EDT 2010

Thanks to Milan for gathering numbers.  Several things to say

Size and performance

| We're talking about a 3% increase in the size of the Map, a 2% size in
| the Map.hs benchmark binary, right? For a 50% increase in Map function performance.

No, I don't think so.  With lots of INLINE, you get a complete copy of the lookup code at *every call site*.  I don't care about the size of Map.o.  But I believe that we saw a major jump in some GHC modules binary size with the new containers thing (like 300).  I don't think we saw anything like a comparable increase in speed.  I think Ian will have the numbers.


One of the things that INLINABLE gives is that client modules can now see the full code for a function, even if it's recursive.  So it is now (at last) relatively straightforward to generate specialisations for INLINABE functions in client modules.  Here's how it'll go.

Currently the specialiser (it focuses only on *overloaded* functions) 
  - Looks for all calls to overloaded functions f, say (f Int d),
	where d is a dictionary
  - Makes a copy of f, specialises it to the dictionary arguments
	passed to that call, and turns that into a new definition
	f_spec = <specialised rhs>
  - Adds a RULE f Int d = f_spec
  - The RHS of f might call other overloaded functions, say g, so when 
	specialising f we might generate new calls to g.  
	So we specialise them too, in a cascade.

At the moment, this only happens for *locally-defined* functions.  But now we have INLINABLE I am going to make it happen for *imported, INLINABLE* functions too.  So if you call (lookup Int d), we'll get a local specialised copy of lookup, and a RULE for lookup.

Handily, the rule will be exposed to clients of *this* module, so they'll see the specialisation too. 

I think I'll also arrange that you can give a SPECIALISE pragma in a client module:
{-# SPECIALISE lookup :: Map Int a -> Int -> Maybe a #-}

None of this will be in GHC 7.0.  I defer to others about whether it could be in a patch release or would await 7.2.


More information about the Libraries mailing list