Search

Calendar

Options

Langs

I really love Mario Klingemann work, and I also enjoy performances and optimizations, so when he made a post on his blog earlier this month about optimization of Perlin Noise, I bookmarked it in order to have a look at it when back from holidays.

I then quickly ported the as code to Haxe. First, most of type-casting things is not useful in Haxe because :

arrays are already typed (even before flash10 vectors)

integer calculus and array access is already optimized

Since the perlin noise algorithm implemented here was relying heavily on integer calculus, I was expecting quite good results. It turned out that for 30 iterations, it took around 14.6 seconds on my new Quadcore CPU for AS3 version and... 5.4 seconds for the Haxe version (woohooo almost 3 times faster !)

Now, having a look at the code, I saw that all the variables were used as statics. It was probably an "optimization" from original PerlinNoise author, which turned out to be bad because - remember it - STATICS ARE SLOW IN FP9 !

So I wrote a second version of the algorithm, without statics, and it went down to 2.7 seconds immediately... After a bit more tunning, it reached the final 2.3 seconds, which correspond to 13 FPS for 256x256 bitmap and 6 times faster than the AS3 code.

Well, setPixel and setPixel32 are awfully slow function to begin with.Maybe you can get a better performance by using setPixels or setVector? Cache the pixel values in a ByteArray or uint Vector and dump it in the bitmap in one go?