Repository navigation
perf(jni): bound completed scan outputs with background prefetch - #11198
Conversation
Adds `CurrentThreadRuntime::block_on_stream_prefetch`, a single-consumer bridge that drives a stream in a background task and keeps at most one completed item ahead of the consumer. JNI scans use it instead of `block_on_stream_thread_safe`, whose per-core output queue retained one finished Arrow batch per core ahead of Java. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Christopher Wirt <[email protected]>
Merging this PR will not alter performance2 warnings
Comparing Footnotes
|
Signed-off-by: Christopher Wirt <[email protected]>
Head branch was pushed to by a user without write access
Resolve the vortex-jni scan.rs conflict with vortex-data#11198: feed the split-concurrency lookahead into block_on_stream_prefetch, and drop scan_iterator, whose only job was to avoid the per-core queue that the prefetch bridge already removes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Christopher Wirt <[email protected]>
Summary
A JNI scan hands batches to Java through
block_on_stream_thread_safe. That bridge queues one completed batch per CPU core, but each JNI stream has only one consumer. On wide or nested Spark scans those queued Arrow batches add up, so peak memory grows with the host's core count.This adds a single-consumer bridge that keeps one completed batch ahead of Java, and uses it for JNI scans.
Result: local Spark measurements, medians of macOS peak physical footprint:
Changes
vortex-io:CurrentThreadRuntime::block_on_stream_prefetch, returning aPrefetchIterator.NativePartition.scanArrowuses it instead ofblock_on_stream_thread_safe. Other callers, including DuckDB, are unchanged.Notes for reviewers
Tests
vortex-io: the one-item-ahead bound, and propagation of a driver panic.On the fork (quantcast#78, same change), the
vortex-iochange is identical. The fork's JNI side goes through ascan_iteratorhelper from #11127 and has a JNI test for it.developdoesn't have that helper yet, so this branch changes theblock_on_stream_thread_safecall directly and leaves out the JNI test. Onlygit diff --checkhas been run on the port.API Changes
CurrentThreadRuntime::block_on_stream_prefetchandPrefetchIteratorinvortex-io. Additive only.AI assistance
Disclosed per the AI policy: AI tools helped write and review this change. Claude Code prepared this upstream port, issue and PR description at my request. I am the responsible contributor.
🤖 Generated with Claude Code