Skip to content

perf: Improve efficiency of array_resize for sliced arrays - #25479

Merged
neilconway merged 3 commits into
apache:mainfrom
neilconway:neilc/fix-resize-sliced
Sep 19, 2026
Merged

neilconway merged 3 commits into
apache:mainfrom
neilconway:neilc/fix-resize-sliced

Conversation

@neilconway

@neilconway neilconway commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • N/A

Rationale for this change

array_resize prepares fill/padding values for the situations in which it needs to grow the input arrays. When (a) no fill value was provided, and (b) no row needs to grow, the code allocated an all-NULL array equal to the size of the underlying backing array of the to-be-resized input. This is redundant, because no fill is needed; it's also potentially expensive, because the backing array might be much larger than the actual visible portion of the input.

Benchmarks:

  • Shrink 500 → 10, omitted fill: 33.79 → 10.61 µs — 3.2× faster.
  • Shrink 10 → 5, omitted fill, 10,000 backing elements: 13.63 → 11.25 µs — about 17% less time.
  • Shrink 10 → 5, omitted fill, 1,000,000 backing elements: 43.36 → 11.24 µs — 3.9× faster.

Other benchmark cases were within noise.

What changes are included in this PR?

  • Refactor build_resized_list to make the fill data Optional
  • When no fill data is needed, don't supply any
  • Add an assert that fill data is supplied if it is needed
  • Add benchmark
  • Add unit tests

What is the testing strategy for this PR?

Benchmarked to confirm performance improvement. Existing tests pass. Added new unit tests to improve code coverage; they are not intended to catch the allocation change though.

Are there any user-facing changes?

No.

@github-actions github-actions Bot added the functions Changes to functions implementation label Sep 18, 2026
@codecov-commenter

codecov-commenter commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.29630% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.38%. Comparing base (3ab72e6) to head (a32e8fe).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/functions-nested/src/resize.rs 96.29% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25479      +/-   ##
==========================================
+ Coverage   82.34%   82.38%   +0.04%     
==========================================
  Files        1137     1138       +1     
  Lines      432364   433776    +1412     
  Branches   432364   433776    +1412     
==========================================
+ Hits       356020   357362    +1342     
- Misses      54830    54855      +25     
- Partials    21514    21559      +45     

☔ 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.

@jayzhan211 jayzhan211 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @neilconway , all minor suggestions

let count = O::usize_as(count);
let start = offset_window[0];
if start + count > offset_window[1] {
debug_assert!(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

debug_assert! is compiled out in release; a violated invariant then becomes an index-OOB panic inside MutableArrayData::try_extend(1, ..). Return an internal error instead:

-            debug_assert!(
-                default_value_data.is_some(),
-                "fill values are required when growing a list"
-            );
+            if default_value_data.is_none() {
+                return internal_err!(
+                    "array_resize: fill values are required when growing a list"
+                );
+            }

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.

Thanks, done.

Comment thread datafusion/functions-nested/src/resize.rs
Comment thread datafusion/functions-nested/benches/array_resize.rs Outdated
@neilconway
neilconway added this pull request to the merge queue Sep 19, 2026
Merged via the queue into apache:main with commit de8803c Sep 19, 2026
41 checks passed
@neilconway
neilconway deleted the neilc/fix-resize-sliced branch September 19, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants