[Haskell-cafe] performance issue and HGL
Jonathan Rockway
jon at jrock.us
Mon Feb 15 03:32:47 EST 2010
* On Sun, Feb 14 2010, Vojtěch Knyttl wrote:
> http://pastebin.dqd.cz/cUmg/
>
> 1. The problem is, that it is very slow. It is obvious that what takes
> the most time is the "mandel" function computation. I have no idea,
> how it can be improved.
Why 1000 iterations? Why is "Infinity" equal to 50? The sequence
usually diverges an order of magnitude sooner than you anticipate, and 2
is considered to be a fine value for Infinity (it makes sense if you
look at the plot).
(Also, "it is obvious what takes the most time"? Did the profiler tell
you that, or are you guessing?)
If you want a really fast implementation, you are going to lose the
simplicity.
I wrote a very simple, multi-thread, mathematically-pure (infinity is
Infinity, the complex numbers are Complex, etc.) a few weeks ago:
http://gist.github.com/291074
It generated this 100M-pixel image in an hour and a half:
http://jrock.us/mandelbrot-big.png
(Warning: apparently that causes many browsers to crash. Gotta love C
programs...)
Anyway, not saying this is a good implementation, but it might give you
some ideas. (The notable "innovation" is that the set membership is
computed in threads, but the image is only generated in the first
thread. This is a limitation of the library I used, but I was still
able to realize massive speed gains by parallelizing: 8 hours of CPU
time in 1.5 hours of wall clock time!)
Reading the Google results for "mandelbrot set" is also enlightening,
and yields optimizations that you may find useful. But when you start
optimizing, you lose "simplicity", so consider first what your goals are
-- a simple implementation, or a really fast implementation. Your needs
might be met by changing iterations to 50 and "infinity" to 2.
So basically, make sure "mandel" is what's slow, then optimize that.
But make sure your plotting is also fast enough -- you are plotting as
many points are you are calculating, after all.
Regards,
Jonathan Rockway
--
Just "another Haskell hacker"
More information about the Haskell-Cafe
mailing list