Skip to content

Optimize exception_ptr, especially for common cases. #44892

@redbeard0531

Description

@redbeard0531
Bugzilla Link 45547
Version unspecified
OS All
CC @mclow

Extended Description

Right now the libc++ exception_ptr type is very expensive to use, even in the cases where it is never or very rarely non-null. Given the intended usage, that is likely to be the common case. This type will become even more important with coroutines, and a poor implementation will handicap the performance of task types, even when the compiler can prove that no exception will be thrown.

Specific improvements:

  • Move optimization. Right now it is copy-only, while moves should be as cheap as for unique_ptr.
  • Swap optimization. Currently only the MSABI implementation has a specialized std::swap. Using the default on intanium abi is very bad right now without move optimizations, but even with them, it should generate better code if customized than if not.
  • Inline trivial operations for null cases, only calling out-of-line helpers for non-null cases. This is especially important for the destructor and move operations since currently the compiler is forced to emit an out of line call, even when it can prove the pointer is null. This would also be useful for copy operations.
  • Comparison to nullptr shouldn't construct an exception_ptr that needs to be destroyed. This may not matter if the prior bullet is done.

Example codegen that should all optimize away: https://godbolt.org/z/NaNKe5

Related libstdc++ bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90295

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillalibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.performance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions