Re:Breaking the Limits: How Folia Made 1,000 Player Minecraf...
by SirYwell on Tuesday June 27, 2023 @04:55AM
(#36490504)
Allocation + deallocation might have more overhead together. I'll try to rephrase: Requesting an object from a pool might have more overhead than allocating a fresh object, and deallocating the object doesn't happen on an application thread but on a GC thread (depending on the GC, obviously).
Alexksey Shipilev has good resources how GCs in HotSpot typically allocate objects (https://shipilev.net/jvm/anatomy-quarks/4-tlab-allocation/).
There definitely are scenarios where pooling might make sense, but basically the low hanging fruits in that area in minecraft are already reaped.
Re:Breaking the Limits: How Folia Made 1,000 Player Minecraf...
by tjoff on Tuesday June 27, 2023 @06:09AM
(#36490963)
I got that, and thanks for the link. But I'm not convinced a pool would have more overhead. It is basically the same thing (not really, but then again, pretty much) just you can encode more information about the usage than a general GC can possible do.
For sure there are other tradeoffs, and whether it is worth it. But when we actually see many GB/s that is not cheap even if you are able to offload to other cores.
The article also concludes:
>It is funny to consider that having TLABs is the way to experience more frequent GC pauses, just because the allocation is so damn cheap!
Sounds like a nightmare, the problem just snowballs, because now you'll be tempted to get into GC tuning.
Re:Breaking the Limits: How Folia Made 1,000 Player Minecraf...
by jandrese on Tuesday June 27, 2023 @01:23PM
(#36496002)
Seems like there should be a performance benefit from not constantly blowing out your L2 cache. If you can keep your object pool hot there should be quite a bit of performance to be gained. The downside is that this would require active memory management (explicitly freeing the objects when you're done with them) and if you have that why bother programming in a GC language in the first place?
Re:Breaking the Limits: How Folia Made 1,000 Player Minecraf...
by zelos on Tuesday June 27, 2023 @07:53AM
(#36491589)
For short lived objects, heap allocation is probably about as fast as allocating on the stack. By pooling you can end up moving objects out of the fast eden space into older generations.
I worked on optimising a java library a few years back and one of the bigger speed ups was removing all the object pooling code.
No idea how to do it in java but a few pointers ought to be enough. You can also omit clearing the memory area between allocations for things that aren't security sensitive, if that is done in java, which I would assume.