Skip to content

fix: reduce peak memory usage when round robin tiebreaker is disabled#23606

Open
ariel-miculas wants to merge 5 commits into
apache:mainfrom
ariel-miculas:reduce-memory-usage-when-rr-disabled
Open

fix: reduce peak memory usage when round robin tiebreaker is disabled#23606
ariel-miculas wants to merge 5 commits into
apache:mainfrom
ariel-miculas:reduce-memory-usage-when-rr-disabled

Conversation

@ariel-miculas

@ariel-miculas ariel-miculas commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Don't pay the memory price when the tie breaking feature is disabled.

What changes are included in this PR?

Mostly tests to show the issue

Are these changes tested?

Yes

Are there any user-facing changes?

No

@github-actions github-actions Bot added core Core DataFusion crate physical-plan Changes to the physical-plan crate labels Jul 15, 2026
Comment thread datafusion/physical-plan/src/sorts/merge.rs Outdated
Comment thread datafusion/physical-plan/src/sorts/merge.rs
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@7f6cc60). Learn more about missing BASE report.

Files with missing lines Patch % Lines
datafusion/physical-plan/src/sorts/merge.rs 91.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #23606   +/-   ##
=======================================
  Coverage        ?   80.65%           
=======================================
  Files           ?     1086           
  Lines           ?   366107           
  Branches        ?   366107           
=======================================
  Hits            ?   295289           
  Misses          ?    53225           
  Partials        ?    17593           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yonipeleg33 yonipeleg33 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice work

Comment on lines +400 to +402
if self.enable_round_robin_tie_breaker {
self.prev_cursors.as_mut().expect("prev_cursor should be set when round robin tie breaker is enabled")[stream_idx] = taken;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expect() check seems a bit redundant, just match on the option directly

Suggested change
if self.enable_round_robin_tie_breaker {
self.prev_cursors.as_mut().expect("prev_cursor should be set when round robin tie breaker is enabled")[stream_idx] = taken;
}
if let Some(prev_cursors) = self.prev_cursors.as_mut() {
prev_cursors[stream_idx] = taken;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would silently break if for some reason a None would end up in prev_cursors, I prefer to fail loudly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants