Skip to content

Reduce sort-based groupby helper build time - #23285

Merged
rapids-bot[bot] merged 9 commits into
NVIDIA:mainfrom
PointKernel:reduce-sort-helper-build-time
Jul 20, 2026
Merged

rapids-bot[bot] merged 9 commits into
NVIDIA:mainfrom
PointKernel:reduce-sort-helper-build-time

Conversation

@PointKernel

@PointKernel PointKernel commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Description

Related to #21973

groupby/sort/sort_helper.cu was the most expensive libcudf TU in a cold build. This PR reduces its build time by moving nested comparator instantiations into a separate TU and removing type-specific gather instantiations.

It uses a two-stage group-offset implementation while keeping the radix-sort path unchanged.

The longest CUDA compile drops from 491s to 65s. The affected object size drops from 7.69 MB to 1.95 MB. Pre-sorted groupby benchmarks improve by 14–22% on B200, while nested-key performance is unchanged.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@copy-pr-bot

copy-pr-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions Bot added libcudf Affects libcudf (C++/CUDA) code. CMake CMake build issue labels Jul 16, 2026
@PointKernel PointKernel added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Jul 16, 2026
@PointKernel

Copy link
Copy Markdown
Member Author

/ok to test 5e46194

@PointKernel PointKernel added the Performance Performance related issue label Jul 16, 2026
@PointKernel
PointKernel marked this pull request as ready for review July 16, 2026 17:54
@PointKernel
PointKernel requested review from a team as code owners July 16, 2026 17:54
@coderabbitai

coderabbitai Bot commented Jul 16, 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: a4607e53-3057-498e-a49a-c1029de0c7af

📥 Commits

Reviewing files that changed from the base of the PR and between 63beb93 and a7f6d10.

📒 Files selected for processing (3)
  • cpp/CMakeLists.txt
  • cpp/src/groupby/sort/sort_helper.cu
  • cpp/src/groupby/sort/sort_helper_group_offsets.cuh
🚧 Files skipped from review as they are similar to previous changes (3)
  • cpp/src/groupby/sort/sort_helper_group_offsets.cuh
  • cpp/CMakeLists.txt
  • cpp/src/groupby/sort/sort_helper.cu

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved nested group-by sorting/grouping by computing group boundaries and unique keys more consistently from pre-sorted keys.
    • Enhanced correctness of group boundary detection for nested columns, including more reliable handling of null values.
  • Performance

    • Streamlined GPU group-offset and unique-key generation for nested group-by workloads, which may improve efficiency for applicable inputs.

Walkthrough

The change extracts sorted groupby offset computation into reusable helpers, adds nested-key support, integrates the helpers into sort_groupby_helper, and materializes a device gather map for unique-key extraction.

Changes

Sorted groupby offset computation

Layer / File(s) Summary
Define group offset helpers
cpp/src/groupby/sort/sort_helper_group_offsets.cuh, cpp/src/groupby/sort/sort_helper_nested.cu, cpp/CMakeLists.txt
Adds generic and nested group-offset helpers and compiles the nested implementation into cudf.
Integrate offset computation
cpp/src/groupby/sort/sort_helper.cu
Routes nested and non-nested keys through the new helpers.
Materialize unique-key gather map
cpp/src/groupby/sort/sort_helper.cu
Builds a device gather map from group offsets before gathering unique keys.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: shrshi

🚥 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%. 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 accurately summarizes the main change: reducing build time for the sort-based groupby helper.
Description check ✅ Passed The description matches the PR changes and clearly explains the build-time and implementation updates.
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.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
cpp/src/groupby/sort/sort_helper.cu (1)

261-261: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Declare the device-lambda return type.
Use -> size_type here to keep this device lambda aligned with the CUDA guideline.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/src/groupby/sort/sort_helper.cu` at line 261, Update the device lambda in
the sort helper’s idx_data accessor to explicitly declare its return type as
size_type using a trailing return type, while preserving its existing parameter
and return expression.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cpp/src/groupby/sort/sort_helper.cu`:
- Line 261: Update the device lambda in the sort helper’s idx_data accessor to
explicitly declare its return type as size_type using a trailing return type,
while preserving its existing parameter and return expression.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: cd0a6f6b-74b7-4c50-8d2a-e7d2d30163f1

📥 Commits

Reviewing files that changed from the base of the PR and between 9131304 and 2bf1811.

📒 Files selected for processing (4)
  • cpp/CMakeLists.txt
  • cpp/src/groupby/sort/sort_helper.cu
  • cpp/src/groupby/sort/sort_helper_group_offsets.cuh
  • cpp/src/groupby/sort/sort_helper_nested.cu

@kingcrimsontianyu kingcrimsontianyu 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.

Looks good!

@PointKernel

Copy link
Copy Markdown
Member Author

/merge

@rapids-bot
rapids-bot Bot merged commit 64a3c78 into NVIDIA:main Jul 20, 2026
130 of 131 checks passed
@PointKernel
PointKernel deleted the reduce-sort-helper-build-time branch July 20, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CMake CMake build issue improvement Improvement / enhancement to an existing function libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change Performance Performance related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants