nsf / pnoise

Perlin noise benchmark
77 stars 23 forks source link

Faster Java impl #10

Open BurntPizza opened 10 years ago

BurntPizza commented 10 years ago

Don't know if it's not "in the spirit" of the bench, but struct-of-arrays is much faster then array-of-structs. It's almost 2x for me.

If you want it to be more consistent with the design of the other impls, at least change Vec2 to be a static inner class, that's about 13% quicker than the existing impl.

nsf commented 9 years ago

Won't accept it, because it's cheating. If SOA vs AOS is indeed the reason for performance boost, I could apply the same for other implementations.

I'm not really comparing how fast you can implement perlin noise using given language, I'm comparing how well a language compiler can optimize the particular code. Minor tweaks such as inlining hints are allowed.

For example I know that if you switch everything in the code from float to double in C# implementation, it gives 30% improvement in performance (1.0s -> 0.7s) on mono. But I'm not sure if I should apply that change as well.

As for turning Vec2 into static inner class (whatever that means, I don't know java and it wasn't me who wrote the java implementation), make a pull request and I'll apply it.

BurntPizza commented 9 years ago

Alright. I guess it's have to wait until Java 10 or whenever value types come in. The reason why SOA is faster in Java's case is because currently Java can't turn small classes into structs, but the programmer can do the equivalent manually via that transformation, removing the indirection from indexing the array of objects to get to their fields and instead simply directly accessing the array of their fields. This will happen automatically once Java gets actual structs. I sent in the other pull request.

asterite commented 9 years ago

@BurntPizza Will Java get actual structs? When is that supposed to happen? Do you have a link?

BurntPizza commented 9 years ago

@asterite Here's as good a link as any, although you can find more through googling "java value types" and "project valhalla"

http://cr.openjdk.java.net/~jrose/values/values-0.html

Also of note is a library by a friend of mine: https://github.com/riven8192/LibStruct