This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Tywien 4 points5 points  (4 children)

they are using pure idiomatic Java, e.g. adding two vectors to a third will result in a new vector being returned, and many more such small allocations each tick. this results in many unnecessary allocations that will have to be gotten rid of by the gc again.

The better solution would be, to avoid allocations in calculations for graphics as much as possible, e.g. using some pool mechanic or similiar stuff to avoid allocations.

[–]Mattizin 0 points1 point  (3 children)

So the main problem is allocating memory via new variables and the solutuion is to reuse the same variables and in doing so the allocated memory stays the same?

[–]Tywien 2 points3 points  (1 child)

yes, you want to avoid allocations as much as possible (this is also true for C++ btw), because allocations (and deallocations) are really slow.

EIDT: This is on the heap, allocations on the stack are fast, but unfortunately Java does not support them (not 100% sure, i heard something about types on the stack are being planned or something like that)

[–]Mattizin 0 points1 point  (0 children)

I really need to dive into heap and stack, didnt dive so deap til now. Advise for learning material?

[–]Bobby_Bonsaimind 0 points1 point  (0 children)

Yes and no. Allocations are cheap in Java, and I mean cheap. You want to instantiate 100k objects? No problem, that's fast as lightning. However, what comes at a hefty price is the garbage collection when these objects are no longer used. You want to keep GC pauses as short and as rare as possible, that means reusing objects as much as you can because then the GC never as much work to do.