Skip to content

PERF: Fast-path COUNT_VALID groupby for no-null inputs - #23756

Open
fallintoplace wants to merge 1 commit into
NVIDIA:mainfrom
fallintoplace:perf-count-valid-no-null-fast-path
Open

PERF: Fast-path COUNT_VALID groupby for no-null inputs#23756
fallintoplace wants to merge 1 commit into
NVIDIA:mainfrom
fallintoplace:perf-count-valid-no-null-fast-path

Conversation

@fallintoplace

@fallintoplace fallintoplace commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Description

  • Use actual null presence instead of nullable metadata in the COUNT_VALID groupby paths.
  • Use a constant-one iterator when the values column has no nulls.
  • Add tests for columns with an allocated all-valid mask.

When there are no nulls, COUNT_VALID has the same input values as COUNT_ALL. The current code still creates a device column view and checks validity for every row.

Benchmark

Added pre_sorted_count_valid_scan in cpp/benchmarks/groupby/group_scan.cpp.

  • Rows: 100K, 1M, 10M, 100M
  • Values: no mask, allocated all-valid mask, and 10% nulls
  • Keys: pre-sorted so sort setup is outside the timed section

Testing

  • pre-commit checks for the changed files pass.
  • Added coverage for sort groupby and groupby scan.

Checklist

  • New or existing tests cover these changes.
  • Documentation is not needed for this internal performance change.

@fallintoplace
fallintoplace requested a review from a team as a code owner August 21, 2026 09:50
@copy-pr-bot

copy-pr-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the libcudf Affects libcudf (C++/CUDA) code. label Aug 21, 2026
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c6d9725e-a830-4f2f-ba76-c8e2c14a238e

📥 Commits

Reviewing files that changed from the base of the PR and between 3780491 and 9008c17.

📒 Files selected for processing (1)
  • cpp/tests/groupby/count_scan_tests.cpp

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • Performance

    • Improved grouped count and count-scan performance for data with no null values.
    • Added benchmarks for pre-sorted grouped count scans across varying row counts and validity patterns.
  • Bug Fixes

    • Corrected null handling so optimized paths are selected based on actual null presence.
  • Tests

    • Added coverage for non-null values, including explicitly allocated validity masks and duplicate grouping keys.

Walkthrough

The change updates groupby count paths to detect actual nulls, adds no-null-mask tests, and introduces a pre-sorted count-scan benchmark with configurable row counts and validity modes.

Changes

Groupby count scan behavior

Layer / File(s) Summary
Null-aware count paths
cpp/src/groupby/sort/group_count.cu, cpp/src/groupby/sort/group_count_scan.cu
Validity processing now runs only when values contain nulls. Null-free values use a constant-one scan.
Count behavior tests
cpp/tests/groupby/count_scan_tests.cpp, cpp/tests/groupby/count_tests.cpp
Typed tests cover explicitly non-null values with allocated no-null masks and verify count results for regular and sort implementations.
Pre-sorted count-scan benchmark
cpp/benchmarks/groupby/group_scan.cpp
The benchmark measures sorted groupby count scans across row counts and value-validity modes and records peak memory usage.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 9008c

This PR adds a localized fast path for COUNT_VALID on inputs without nulls and includes targeted test coverage; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: abigalekim, misiugodfrey, bdice

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main performance change for COUNT_VALID groupby operations without nulls.
Description check ✅ Passed The description directly explains the optimization, benchmarks, tests, and performance rationale in the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@davidwendt

Copy link
Copy Markdown
Contributor

Can you post the benchmark results?

@davidwendt davidwendt added 3 - Ready for Review Ready for review by team improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Aug 21, 2026
Comment thread cpp/tests/groupby/count_scan_tests.cpp Outdated
test_single_scan(keys, vals, expect_keys, expect_vals, std::move(agg2));
}

TYPED_TEST(groupby_count_scan_test, all_valid_values)

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.

I'm not sure this warrants a typed-test. Can we reduce this to a single type so we do not generate 20 of these?

@fallintoplace
fallintoplace force-pushed the perf-count-valid-no-null-fast-path branch from 3780491 to 9008c17 Compare August 21, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 - Ready for Review Ready for review by team improvement Improvement / enhancement to an existing function libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants