On Mon, Jan 6, 2020 at 7:09 PM Matt Sicker <boa...@gmail.com> wrote:
> Would it be useful to implement some sort of buffer pool for
> StringBuilders and ByteBuffers? Could likely copy code from netty's
> util library (ByteBuf et al.) or reuse stuff from commons-pool if
> needed. This would work properly in applications, servlets, and even
> reactive streams and lightweight threads later on.

Would you mind elaborating a little bit more on the idea you have in
mind, please? To get the discussion going, I have the following draft:

    public interface ObjectPool<V> {
        V acquire();
        void release(V instance);
    }

    public interface ObjectPoolFactory {
        // For char[], byte[], ByteBuffer, etc. (Types that cannot get
extended implicitly.)
        ObjectPool<V> create(Class<V> clazz, Supplier<V> objectFactory);
        // For StringBuilder, etc. (Types that can get extended implicitly.)
        ObjectPool<V> share(Class<V> clazz);
    }

One can pretty efficiently implement such an ObjectPool<V>, e.g., via
a JCTools[1] MPMC queue. Though note that object pools necessitate
manual object release, which is not the case for TLA-provided objects.

Providing a shared object pool factory to the rest of the code base
might need a little bit more thinking.

Exposing configuration knobs to enforce certain limits on the pool and
its factory is also a question that needs to be addressed.

[1] https://github.com/JCTools/JCTools/

Reply via email to