Optimize NibbleArray to use pooled buffers
Massively reduces memory allocation of 2048 byte buffers by using an object pool for these.
This commit is contained in:
@@ -2090,18 +2090,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+public final class PooledObjects<E> {
|
||||
+
|
||||
+ public static final PooledObjects<MutableInt> POOLED_MUTABLE_INTEGERS = new PooledObjects<>(new PooledObjectHandler<MutableInt>() {
|
||||
+ @Override
|
||||
+ public MutableInt createNew() {
|
||||
+ return new MutableInt();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void onAcquire(final MutableInt value) {}
|
||||
+
|
||||
+ @Override
|
||||
+ public void onRelease(final MutableInt value) {}
|
||||
+ }, 200, -1);
|
||||
+ public static final PooledObjects<MutableInt> POOLED_MUTABLE_INTEGERS = new PooledObjects<>(MutableInt::new, 200, -1);
|
||||
+
|
||||
+ private final PooledObjectHandler<E> handler;
|
||||
+ private final int maxPoolSize;
|
||||
@@ -2171,16 +2160,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ }
|
||||
+
|
||||
+ /** This object is restricted from interacting with any pool */
|
||||
+ static interface PooledObjectHandler<E> {
|
||||
+ public static interface PooledObjectHandler<E> {
|
||||
+
|
||||
+ /**
|
||||
+ * Must return a non-null object
|
||||
+ */
|
||||
+ E createNew();
|
||||
+
|
||||
+ void onAcquire(final E value);
|
||||
+ default void onAcquire(final E value) {}
|
||||
+
|
||||
+ void onRelease(final E value);
|
||||
+ default void onRelease(final E value) {}
|
||||
+ }
|
||||
+
|
||||
+ protected static class IsolatedPool<E> {
|
||||
|
||||
Reference in New Issue
Block a user