Skip to content

<exception>: Optimize exception_ptr operations - #6403

Open
nt (namtran1812) wants to merge 3 commits into
microsoft:mainfrom
namtran1812:investigate/exception-ptr-6387
Open

<exception>: Optimize exception_ptr operations#6403
nt (namtran1812) wants to merge 3 commits into
microsoft:mainfrom
namtran1812:investigate/exception-ptr-6387

Conversation

@namtran1812

Copy link
Copy Markdown

Summary

Optimizes several std::exception_ptr operations that currently call out-of-line CRT helpers even though the representation is already known in <exception>.

This change:

  • makes the default constructor and nullptr_t constructor rely on the existing null member initializers
  • implements operator bool() as _Data1 != nullptr
  • compares _Data1 directly in operator==
  • swaps _Data1 and _Data2 directly
  • implements assignment from nullptr_t using swap-with-empty, avoiding __ExceptionPtrAssign

The exported CRT helper functions remain unchanged for ABI compatibility.

Fixes #6387.

Rationale

exception_ptr is intentionally laid out to match shared_ptr<const _EXCEPTION_RECORD>. Its two data members correspond to the shared pointer's stored pointer and control block, and the implementation already contains a static_assert enforcing matching size and alignment.

The removed out-of-line calls currently perform operations equivalent to the inlined implementations above:

  • __ExceptionPtrCreate default-constructs an empty shared_ptr
  • __ExceptionPtrToBool converts the underlying shared_ptr to bool
  • __ExceptionPtrCompare compares the underlying shared_ptr
  • __ExceptionPtrSwap swaps the underlying shared_ptr

For operator=(nullptr_t), swapping with an empty exception_ptr preserves ownership semantics and allows the temporary's destructor to release the previous control block correctly.

Validation

The existing Dev11_0299014_exception_ptr_requirements test already exercises the affected semantics, including:

  • default and nullptr construction
  • bool conversion
  • equality between empty, aliased, and distinct exception pointers
  • assignment from nullptr
  • swapping
  • self-swap

No ABI-visible layout or exported CRT symbol is changed.

Copilot AI balanced review requested due to automatic review settings August 15, 2026 17:55
@namtran1812
nt (namtran1812) requested a review from a team as a code owner August 15, 2026 17:55
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Aug 15, 2026
@azure-pipelines

This comment was marked as resolved.

This comment was marked as resolved.

@namtran1812

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI review requested due to automatic review settings August 15, 2026 18:27
@namtran1812

This comment was marked as resolved.

This comment was marked as resolved.

@namtran1812

This comment was marked as resolved.

@namtran1812

This comment was marked as resolved.

AlexGuteniev

This comment was marked as resolved.

@github-project-automation github-project-automation Bot moved this from Initial Review to Work In Progress in STL Code Reviews Aug 24, 2026
@StephanTLavavej

This comment was marked as resolved.

@StephanTLavavej

This comment was marked as resolved.

@namtran1812

This comment was marked as resolved.

Copilot AI review requested due to automatic review settings September 2, 2026 21:40
@namtran1812

This comment was marked as resolved.

This comment was marked as resolved.

@StephanTLavavej

This comment was marked as resolved.

@azure-pipelines

This comment was marked as resolved.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Work In Progress to Initial Review in STL Code Reviews Sep 3, 2026
@namtran1812

Copy link
Copy Markdown
Author

Hi! All CI checks are passing now. When you have a chance, could someone from @microsoft/vclibs take another look? Thanks!

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

Labels

performance Must go faster

Projects

Status: Initial Review

Development

Successfully merging this pull request may close these issues.

<exception>: Optimize exception_ptr a bit

5 participants