Unpack primitive types by default in data

Johan Tibell johan.tibell at gmail.com
Fri Feb 17 21:10:57 CET 2012


On Fri, Feb 17, 2012 at 4:40 AM, Simon Marlow <marlowsd at gmail.com> wrote:
> On 17/02/2012 00:25, Johan Tibell wrote:
>>
>> Hi all,
>>
>> I've been thinking about this some more and I think we should
>> definitely unpack primitive types (e.g. Int, Word, Float, Double,
>> Char) by default.
>
>
> Why only primitive types?  I think you probably want to do it for any type
> that unpacks to a single word (or maybe at most 2 words? another thing to
> tune).

That's what I mean by primitive, anything that unpacks to the size of
a pointer (perhaps with an exception for Double.) We can certainly try
other sizes, but there are reasons to believe the single word case is
special. Given:

    data T a = C !Int a

    f :: T -> Int -> T
    f (C x y) z = C z y

the same number of words has to be copied to construct the result
value whether the Int fields is unpacked or not. If you unpack bigger
things you might need to do more work when constructing new values.

> nofib probably has, to a first approximation, zero strictness annotations.
>  Because most of the programs in there predate the addition of strictness
> annotations to Haskell.

That's good for us. The downside of nofib is that it probably doesn't
represent real world Haskell programs well, as they tend to use more
packed types, such as ByteString, Text, and Vector. Still, it's a good
start.

> GHC itself would be a good benchmark, incidentally...

Indeed, that's what I thought as well. How do I test the build time of
GHC? By building my modified GHC in one build tree and then use it to
build another GHC in another (clean) build tree?

-- Johan



More information about the Glasgow-haskell-users mailing list