Mandelbrot

I’ve dragged the Mandelbrot script from day 17 of the Advent calendar kicking and screaming to the current version of Rakudo. The big hurdle turned out to be an under-spec’d and poorly implemented corner of Range. If you specified the size on the command line, then the width / height was a string. And, well:

> say (^"501").eager.perl
(0, 1, 2, 3, 4, 5)

Once I converted width / height to a numeric type, the script worked fine.

Martin Berends wrote a beautiful little Perl 5 script to monitor run time and memory usage on a Linux box, enabling me to do a profile of how Rakudo behaves when you bump up the size of the Mandelbrot set we calculate. There is both good and bad news on this front.

The good news: we would expect that doubling the length of an edge would quadruple the time taken. Because each line of the set is output as we go, we would expect doubling the edge length would memory double the memory required. In both cases, that is exactly what we see, which means there are no unexpected N^2 or worse issues.

The bad news: The code is very slow, and worse, it uses insane amounts of memory. Generating a 1001x1001 Mandelbrot set -- an operation that should only use the memory required to store 1001 Complex numbers in an array and 1001 ints in another array -- takes 6.4 GB of memory. Obviously that's not what we're seeing, as a quick test script I just wrote shows that you can create both those arrays in under 25MB of memory. So something else is eating up memory at a ferocious rate.

About these ads

2 Responses to “Mandelbrot”

  1. Dave Says:

    Did chromatic and Vasily Chekalkin’s rakudo memory savings bug fixes fix this? See his posts below for more info.

    http://www.modernperlbooks.com/mt/2010/04/the-tyranny-of-memory-part-i-shared-buffers.html

    http://www.modernperlbooks.com/mt/2010/04/the-tyranny-of-memory-part-ii-reifying-cows.html

    http://www.modernperlbooks.com/mt/2010/04/the-tyranny-of-memory-part-iii-dont-copy-that-string.html

    http://www.modernperlbooks.com/mt/2010/04/the-tyranny-of-memory-part-iv-immutable-strings.html

    • colomon Says:

      Good question. This was with the latest Rakudo from github as of 4/17/2010. I don’t know if chromatic’s patches are in that build or not.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: