4 ms·
> i dont think you need value types at all, and you can simulate it by using byte buffers with an abstraction on top of it. After all, what's the difference bet
by slver 6y ago
> i dont think you need value types at all, and you can simulate it by using byte buffers with an abstraction on top of it. After all, what's the difference between value types and a byte array?
The difference is a bit like coding in Java vs coding in assembler (more below in an example).
> The only reason java gets poor performance is the coder doing java is too used to producing garbage (or is too inexperienced to write high performance java code).
Read about Entity Component Systems, the leading architecture of high-performance game engines these days.
To do this in Java, with the implied memory locality, would basically mean storing your entire game state in bytebuffers, and constantly unpacking and packing them to do any operation on them. And when you unpack them if you unpack them to a random object in heap, you negate the entire purpose of the locality of a bytebuffer. So you somehow need to do the job raw, reading everything inline and putting it back inline, so you can stay on the stack.
I also doubt that the get/put calls you'd need to do to get/set every number would be free. So performance would probably end up quite terrible.
> you can easily avoid most performance problems in memory by pre-allocating and reusing memory by pooling.
If you make an object pool in Java you'll save on memory alloc/dealloc. You won't achieve memory locality, so your code will be much slower than languages where you can do that.
- kaba0 6y agoHaving thousand NPC objects around is no problem at all. The rendering part is the only thing critical/numerous enough that you may have to optimize to such a low level.
- slver 6y agoNot sure what you cover by "NPC objects" but they easily can participate in physics and AI as well (or at least basic scripted behavior). Also significant game state is not only represented by renderable content.
- kaba0 6y agoWell, if it’s physics as well, then yeah having a separate NPC objects may not be the best idea (though if the physics engine awaits some primitives, like for each “object” 3 coordinates before simulation, and then sets the corresponding position on each NPC, it may be fast enough). But Valhalla really is coming, and until many many games have more than enough performance packed in the JVM already.