[Haskell-cafe] Re: ANN: HLint 1.2

2009-01-13 Thread Max Bolingbroke
2009/1/13 Simon Marlow :
>> GHC should indeed be doing so. I'm working (on and off) to work out
>> some suitable heuristics and put the transformation into ghc -O2.
>> There are a few wrinkles that still need sorting out, but preliminary
>> indications are that it decreases the runtime of our standard
>> benchmark suite, nofib, by 12% or so.
>
> !!!
>
> That's a surprising result - have you looked closely at the places where the
> transformation is having a big effect to see what's going on?

Yes, it is rather better than I expected :-)

The main gains seem to come from specialising higher-order functions
on particular arguments, like we saw earlier in this thread. There
seem to be a number of suitable functions in the standard library that
aren't written in static-argument-transformed (SATed) style.

Another gain comes from the nofib program "atom", which has a function
a lot like this:

f x y z = (x, y, z) : f x y z

Once this is SATed it becomes a much better function:

f = let f' = (x, y, z) : f'
 in f'

Which decreases runtime of atom by 97% :-)

The catch is that things written in this style can actually be worse
than their lambda-lifted brethren. This happens for 3 main reasons:

1) SATed functions tend to have case liberation applied to them
instead of constructor specialisation. Case liberation kind of sucks
in comparison to constructor specialisation, so bad things happen
(increased allocations and code size)
2) Carrying around a single variable in the SAT closure just adds
indirection to the generated code with no benefits, so it's better to
remove that indirection (by lambda lifting) just before going to STG -
but be careful not to change the unfolding!
3) More SATing means more expressions are loop invariant. This is
usually a good thing, but if you float a loop-invariant out of a "cold
branch" of a recursive function (a branch that is actually only
entered once dynamically) then you end up eagerly allocating a closure
for the loop-invariant thing which may never be entered. This is sort
of a bug in our current float-out pass.

Like I said, I'm working on improving the situation with 1 and 2,
which need to be resolved to iron out some of the bad cases in nofib.
I need to find time to take a look at this though.

Cheers,
Max
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: ANN: HLint 1.2

2009-01-13 Thread Simon Marlow

Max Bolingbroke wrote:

2009/1/12 Jan-Willem Maessen :

On Jan 12, 2009, at 9:01 AM, Duncan Coutts wrote:


No because the current definition are recursive and ghc cannot inline
recursive functions.



Then the map can be inlined at the call site and the 'f' inlined into
the body of 'go'.

This seems like exactly the sort of mechanical transformation that computers
do quickly and accurately, and humans get wrong.  Surely it wouldn't be that
hard for GHC to transform self recursion in this way (possibly subject to
the condition that the result be worth inlining)?


GHC should indeed be doing so. I'm working (on and off) to work out
some suitable heuristics and put the transformation into ghc -O2.
There are a few wrinkles that still need sorting out, but preliminary
indications are that it decreases the runtime of our standard
benchmark suite, nofib, by 12% or so.


!!!

That's a surprising result - have you looked closely at the places where 
the transformation is having a big effect to see what's going on?


Cheers,
Simon
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: ANN: HLint 1.2

2009-01-12 Thread Juan Antonio Zaratiegui Vallecillo, a.k.a. Zara
Neil Mitchell escribió:
> Hi
> 
>> Does GHC specialize map?  If it doesn't, then hand crafted version
>> could be faster.
> 
> GHC doesn't specialize map, and a hand-crafted one could be faster -
> but you then wouldn't get foldr/build fusion. In general HLint tries
> to make the code prettier, but sometimes you will need to deviate from
> its suggestions when you've profiled etc. To stop HLint warning you
> just create Hints.hs and include the line "ignore =
> LennartsSuperFastModule.mySpecialisedMap" - full details in the
> manual.
> 

I am really happy with HLint. Being relatively new to haskell world, I
tend to be slow in finding ready-made solutions, or using folds fot
recursive tasks.

HLint 1.0 discovers `on` for me, and only for that I will be infinitely
grateful.

Now, if HLint 1.2 helps me with the map/fold understanding, I will be
'continuous infinitely' grateful (although real numbers are not
representable!)

Best regards,

Zara

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe