
On Thu, Aug 09, 2007 at 10:19:59PM +0100, Andrew Coppin wrote:
Right. So a Bool is a 32 or 64 bit quantity. (Rather like Smalltalk...)
That presumably means that a (Double,Double) is going to be a thunk that evaluates to a (,) pointing to two thunks that evaluate to pointers... IOW, something like 3 pointers' worth of space.
I like pretty pictures. : : +--------+ : : /->| D# tag | +-----------+ +---------+ / +--------+ +--------+ | somewhere |--->| (,) tag |-/ | Value | /->| D# tag | +-----------+ +---------+ | | | +--------+ : : | fst | | | | | Value | : : +---------+ +--------+ | | | | snd |-----------------/ | | +---------+ +--------+ That's how much space a (Double,Double) NF uses.
Whereas my Quad object is going to be a pointer to one of 4 values... so it looks like Quads save space. (And they're more strict.) OTOH, I'm not sure what the time penalty is like...
Probably none. The STG-machine was designed to make user-defined algebraic types very fast.
It would be nice if there were some general mechanism for turning a bunch of Bool flags into a single machine word. E.g., if I did a
data Foo = Foo {flagX, flagY, flagZ :: !Bool}
and it ends up that a Foo value is just a single machine word, and GHC picks which bit each flag is... I guess if you want that at present you'd have to code it all by hand. Hmm, I think this might work out better than my current Quad thing... I could do something like
type Quad = Word8
foo q = let x = if testBit 0 q ... y = if testBit 1 q ...
That should be quite fast... (?)
Probably. I wound up doing something similar with vty, to considerable gain. (I did however use .&. instead of testBit - probably makes no difference, but I'm reminded of the (^2) being much slower than join(*) case...)
(Questions, questions, so many questions...)
I like answering them. :)
Heh. I'll have to pester you more often. :-P
:)
PS. Somewhere they should write a page entitled "Optimisations that GHC does (and doesn't) do"...
Good idea! Maybe it could be fit into the GHC Performance Resource somehow? (http://www.haskell.org/haskellwiki/Performance/GHC)
PPS. Hmm. Might be out of date fast? ;-)
That's what wikis are for :) Stefan