Repository navigation
perf(jni): bound completed scan outputs with background prefetch - #11198
Open
ChristopherWirt wants to merge 2 commits into
Open
ChristopherWirt wants to merge 2 commits into
ChristopherWirt wants to merge 2 commits into
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 <noreply@anthropic.com> Signed-off-by: Christopher Wirt <cwirt@quantcast.com>
robert3005
approved these changes
Nov 4, 2026
Merging this PR will degrade performance by 11.06%1 warning
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
robert3005
enabled auto-merge (squash)
November 5, 2026 00:52
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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