Skip to content

Commit 0be931c

Browse files
committed
Start calculating inner's first item concurrently.
- this should improve the performance of the pipeline now that it schedule up to N-calculations of the inner's first cursor item, where N is the size of the pipeline.
1 parent 847ffe6 commit 0be931c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/cursors/FlatMapPipelinedCursor.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ private synchronized void addEntryToPipeline(PipelineQueueEntry pipelineQueueEnt
267267
if (closed) {
268268
pipelineQueueEntry.close();
269269
}
270+
pipelineQueueEntry.getNextInnerPipelineFuture();
270271
pipeline.add(pipelineQueueEntry);
271272
}
272273

@@ -295,20 +296,26 @@ public PipelineQueueEntry(RecordCursor<V> innerCursor,
295296
this.priorOuterContinuation = priorOuterContinuation;
296297
this.outerResult = outerResult;
297298
this.outerCheckValue = outerCheckValue;
299+
// start calculating the next result in the background.
300+
setInnerFuture();
298301
}
299302

300303
@Nonnull
301304
public CompletableFuture<PipelineQueueEntry> getNextInnerPipelineFuture() {
302305
if (innerFuture == null) {
303-
if (innerCursor == null) {
304-
innerFuture = CompletableFuture.completedFuture(RecordCursorResult.exhausted());
305-
} else {
306-
innerFuture = innerCursor.onNext();
307-
}
306+
setInnerFuture();
308307
}
309308
return innerFuture.thenApply(vignore -> this);
310309
}
311310

311+
private void setInnerFuture() {
312+
if (innerCursor == null) {
313+
innerFuture = CompletableFuture.completedFuture(RecordCursorResult.exhausted());
314+
} else {
315+
innerFuture = innerCursor.onNext();
316+
}
317+
}
318+
312319
public boolean doesNotHaveReturnableResult() {
313320
if (innerCursor == null || // Hit sentinel, so we have a returnable result
314321
innerFuture == null || // Inner future hasn't been started yet.

0 commit comments

Comments
 (0)