pnoise icon indicating copy to clipboard operation
pnoise copied to clipboard

Faster Java impl

Open BurntPizza opened this issue 11 years ago • 4 comments

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.

BurntPizza avatar Nov 11 '14 22:11 BurntPizza

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.

nsf avatar Nov 12 '14 07:11 nsf

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.

BurntPizza avatar Nov 12 '14 14:11 BurntPizza

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

asterite avatar Nov 12 '14 14:11 asterite

@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

BurntPizza avatar Nov 12 '14 14:11 BurntPizza