There is a number of types of object pools. In each case the behaviour needs to be optimised for their use case so the cost of using them is faviourable compared with straightforward reallocating and the extra complexity involved.
In the case of buffers for IO you have problem that if you are going to optimise allocation, you can avoid zeroing out the buffer and perform determistic releasing which is otherwise a high proportion of the cost. Ie by using Unsafe allocate and free memory directly. You can use this with file descriptors (which has numerous portability issues) but you might find doing this (when it is an option) means you no longer need an object pool.
What are the valid cases for object pooling on the JVM? What are the invalid use cases for object pooling?It is generally considered a win in native code since frequent malloc/free pairs can make quite a dent in performance. Object pooling's interaction with GC seems complicated. On the one hand it generates fewer objects that need to be tracked. Conversely it also creates a bunch of long lived objects.
--The Netty project is especially interesting to me since I am interested in the properties of pooled buffers for the purpose of holding network data. Netty 4.0 implemented a Jemalloc like memory allocator for it's buffers. It would be great if it's maintainers (I know you guys are on the list :-) ) could talk about the impact on some of their projects and any gotchas/lessons learnt. It would be especially enlightening to learn not only about the impact on time taken to allocate a buffer but also about impact on the rest of the application performance (with less garbage being generated). Would love to hear from other developers too.Thanks!
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Depending on how you write them, an object pool of immutable objects doesn't need to be thread safe in the traditional sense. As long as each thread behaves correctly, that is what matters.