Repository navigation
Commit b9d7594
perf(jni): bound completed scan outputs with background prefetch (#11198)
## Summary
- Tracking Issue: #11197
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:
| Workload | Runs | Peak GiB, before → after | Change |
| --- | ---: | ---: | ---: |
| Flat-layout read | 3 | 1.46 → 1.05 | −28% |
| List-layout read | 2 | 3.25 → 2.22 | −32% |
| Ordered Vortex rewrite | 2 | 1.86 → 1.43 | −23% |
- Batch sizes, compression and decode concurrency don't change. The
rewrite's output was identical in size and row count.
- Timing was too noisy on a shared host to claim a speedup or rule out a
regression. Only one Spark task with four native workers was measured.
## Changes
- **`vortex-io`:** `CurrentThreadRuntime::block_on_stream_prefetch`,
returning a `PrefetchIterator`.
- It drives the stream in a background task, so native work still
overlaps Java consumption.
- It keeps at most one completed item ahead of the consumer, and skips
entering the executor when an item is already waiting.
- Dropping it cancels the producer. A producer panic is re-raised at end
of stream.
- **JNI:** `NativePartition.scanArrow` uses it instead of
`block_on_stream_thread_safe`. Other callers, including DuckDB, are
unchanged.
---------
Signed-off-by: Christopher Wirt <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>1 parent 42e47a7 commit b9d7594
2 files changed
Lines changed: 114 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
91 | 93 | | |
92 | 94 | | |
93 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
94 | 125 | | |
95 | 126 | | |
96 | 127 | | |
| |||
184 | 215 | | |
185 | 216 | | |
186 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
187 | 244 | | |
188 | 245 | | |
189 | 246 | | |
| |||
627 | 684 | | |
628 | 685 | | |
629 | 686 | | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
630 | 720 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
379 | 375 | | |
380 | | - | |
381 | | - | |
382 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
383 | 386 | | |
384 | 387 | | |
385 | 388 | | |
| |||
0 commit comments