Skip to content

[libcu++] Reduce tuple and pair constraint instantiations - #10858

Closed
abdeltaehass wants to merge 1 commit into
NVIDIA:mainfrom
abdeltaehass:agent/10846-tuple-pair-compile-time
Closed

[libcu++] Reduce tuple and pair constraint instantiations#10858
abdeltaehass wants to merge 1 commit into
NVIDIA:mainfrom
abdeltaehass:agent/10846-tuple-pair-compile-time

Conversation

@abdeltaehass

Copy link
Copy Markdown
Contributor

Summary

  • replace four global inline-variable constructor selectors with private static consteval helpers
  • remove tuple's intermediate integral_constant constructor aliases
  • keep the existing selector functions, constraint ordering, overload participation, and noexcept expressions unchanged

Closes #10846.

This is a deliberately smaller alternative to #10719. That PR is broader and centralizes tuple/pair construction, assignment, and comparison constraints; this PR only removes the measured constructor-selector variable-template layer.

Compile-time measurements

Measured with Apple Clang 21.0.0 using the same generated source, SDK, standard library, flags, and alternating run order against an unchanged upstream/main worktree.

Configuration Metric Before After Change
C++20, 256 unique cases, 8 runs mean wall time 8.82375 s 8.69375 s -1.47%
C++20, 256 unique cases, 8 runs median wall time 8.670 s 8.570 s -1.15%
C++20, 256 unique cases, 8 runs mean user CPU time 8.41250 s 8.27125 s -1.68%
C++17, 128 unique cases, 10 runs mean wall time 5.303 s 5.244 s -1.11%
C++17, 128 unique cases, 10 runs median wall time 5.310 s 5.240 s -1.32%

A C++20 Clang trace with 128 unique cases showed the four targeted inline-variable initializers falling from 4,096 evaluations to zero. Total EvaluateAsInitializer events fell from 32,780 to 28,681.

The smaller C++20 128-case wall-time series was neutral by mean (4.377 s to 4.375 s), so no improvement is claimed for that series.

Validation

  • 32 directly affected positive tuple/pair constructor programs passed under C++17
  • the same 32 programs passed under C++20
  • 10 expected-negative constructor sources remained rejected under C++17
  • the same 10 remained rejected under C++20
  • generated optimized assembly was byte-for-byte identical before/after under C++17 and C++20
  • file-scoped pre-commit passed for all three modified headers
  • git diff --check passed

Not run locally: the official CMake/lit suite, NVCC/device tests, GCC, MSVC, or GPU tests because those toolchains were unavailable.

@abdeltaehass
abdeltaehass requested a review from a team as a code owner August 17, 2026 23:42
@abdeltaehass
abdeltaehass requested a review from fbusato August 17, 2026 23:42
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Aug 17, 2026
@copy-pr-bot

copy-pr-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

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.

@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Aug 17, 2026
@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

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: 415d4c06-ce06-4220-a3b3-819b06a6c5f6

📥 Commits

Reviewing files that changed from the base of the PR and between 0461a7e and dc1ecb6.

📒 Files selected for processing (3)
  • libcudacxx/include/cuda/std/__tuple_dir/tuple.h
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_constraints.h
  • libcudacxx/include/cuda/std/__utility/pair.h
💤 Files with no reviewable changes (1)
  • libcudacxx/include/cuda/std/__tuple_dir/tuple_constraints.h

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


📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved compile-time handling for cuda::std::tuple and cuda::std::pair constructors.
    • Deferred tuple-like constraint evaluation to prevent recursive template instantiation issues.
    • Preserved existing constructor behavior, parameter syntax, and noexcept calculations.

Walkthrough

Changes

The PR replaces eagerly instantiated tuple and pair constructor constraint aliases and variable templates with immediate selector functions. It updates variadic, tuple-like, allocator-aware, forwarding, converting, explicit, implicit, and deleted constructors.

Suggested reviewers: fbusato, miscco, jacobfaib

Changes

Tuple and pair constructor constraints

Layer / File(s) Summary
Tuple selector functions and variadic constructors
libcudacxx/include/cuda/std/__tuple_dir/tuple.h, libcudacxx/include/cuda/std/__tuple_dir/tuple_constraints.h
Tuple defines immediate variadic and tuple-like selectors. Variadic, allocator-aware, and reduced-rank constructors use the selectors. The former variable-template wrappers are removed.
Tuple-like constructors
libcudacxx/include/cuda/std/__tuple_dir/tuple.h
Tuple-like constructors use deferred selector calls across lvalue, rvalue, forwarding, allocator-aware, implicit, explicit, and deleted overloads.
Pair constructor selection
libcudacxx/include/cuda/std/__utility/pair.h
Pair adds private selector helpers and updates element-wise, converting, forwarding, implicit, explicit, and deleted constructors. The obsolete pair-like variable template is removed.

Assessment against linked issues

Objective Addressed Explanation
Investigate and apply compile-time improvements for tuple and pair constructor constraint checks [#10846]

Suggested reviewers: fbusato, miscco, jacobfaib

Merge Risk: ⚪ Minimal · up to dc1ec

This PR reduces compile-time constraint-instantiation overhead while preserving constructor behavior and overload participation; no actionable merge-blocking risk remains beyond normal checks and review.


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

@jrhemstad

Copy link
Copy Markdown
Collaborator

Closing per #10846 (comment)

@jrhemstad jrhemstad closed this Aug 18, 2026
@abdeltaehass
abdeltaehass deleted the agent/10846-tuple-pair-compile-time branch August 18, 2026 04:36
Comment on lines -165 to -166
// Old MSVC chokes about a static constexpr variable needing an initializer. Work around by using a type
template <class... _UTypes>

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.

There was a fence here for a reason.
The problem is that old MSVC needs to go through an explicit type instantiation in this case. So this would not have compiled with older MSVC

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

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[FEA]: Improve compile times of tuple and pair

3 participants