Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions core/sail/lmdb/src/main/java/org/eclipse/rdf4j/sail/lmdb/Pool.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ class Pool {
// thread-local pool instance
private static final ThreadLocal<Pool> threadlocal = ThreadLocal.withInitial(Pool::new);

private final MDBVal[] valPool = new MDBVal[1024];
private final ByteBuffer[] keyPool = new ByteBuffer[1024];
private final MDBVal[] valPool = new MDBVal[2048];
private final ByteBuffer[] keyPool = new ByteBuffer[2048];
private final Statistics[] statisticsPool = new Statistics[512];
private final LmdbRecordIterator.State[] statePool = new LmdbRecordIterator.State[128];
private int valPoolIndex = -1;
private int keyPoolIndex = -1;
private int statisticsPoolIndex = -1;
private int statePoolIndex = -1;

final MDBVal getVal() {
if (valPoolIndex >= 0) {
Expand All @@ -36,6 +38,13 @@ final MDBVal getVal() {
return MDBVal.malloc();
}

final LmdbRecordIterator.State getState() {
if (statePoolIndex >= 0) {
return statePool[statePoolIndex--];
}
return new LmdbRecordIterator.State();
}

final ByteBuffer getKeyBuffer() {
if (keyPoolIndex >= 0) {
ByteBuffer bb = keyPool[keyPoolIndex--];
Expand Down Expand Up @@ -74,7 +83,18 @@ final void free(Statistics statistics) {
}
}

final void free(LmdbRecordIterator.State state) {
if (statePoolIndex < statePool.length - 1) {
statePool[++statePoolIndex] = state;
} else {
state.close();
}
}

final void close() {
while (statePoolIndex >= 0) {
statePool[statePoolIndex--].close();
}
while (valPoolIndex >= 0) {
valPool[valPoolIndex--].close();
}
Expand Down
Loading
Loading