[Haskell-cafe] When does the UNPACK pragma work?

Eugene Kirpichov ekirpichov at gmail.com
Fri Oct 28 11:41:15 CEST 2011


Hi,

I'm trying to speed up Data.Time (the time package) 'cause my program is
spending a very substantial fraction of time manipulating dates.

I decided to start with strictifying and unpacking the date/time types, as
there's no point in having them be lazy and I indeed had a lot of allocation
in date/time arithmetic in my performance profile.

data UTCTime = UTCTime {
    utctDay :: {-# UNPACK #-} !Day,
    utctDayTime :: {-# UNPACK #-} !DiffTime
}

(unpacks and strictness mine)

newtype Day = ModifiedJulianDay {toModifiedJulianDay :: Integer}
newtype DiffTime = MkDiffTime Pico

And Pico is also essentially a newtype for Integer.

So, I'm getting warnings on this definition of UTCTime.
QUESTION: Is it the case that I can only UNPACK primitive fields, and not
even their newtypes?

Data\Time\Clock\UTC.hs:30:16:
    Warning: Ignoring unusable UNPACK pragma on the
             first argument of `UTCTime'
    In the definition of data constructor `UTCTime'
    In the data type declaration for `UTCTime'

Data\Time\Clock\UTC.hs:30:16:
    Warning: Ignoring unusable UNPACK pragma on the
             second argument of `UTCTime'
    In the definition of data constructor `UTCTime'
    In the data type declaration for `UTCTime'



-- 
Eugene Kirpichov
Principal Engineer, Mirantis Inc. http://www.mirantis.com/
Editor, http://fprog.ru/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111028/15418ac4/attachment.htm>


More information about the Haskell-Cafe mailing list