Reduce CoreCLR C++ exception cleanup overhead - #134835
Merged
davidwrighton merged 2 commits intoSep 29, 2026
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @agocke |
jkotas
reviewed
Sep 29, 2026
Member
Author
|
Need to try -fassume-nothrow-exception-dtor |
This was referenced Sep 29, 2026
Member
|
Can/should we use |
Member
Author
|
@huoyaoyuan Using noexcept can cause extra generation of EH handling infrastructure, due to the interaction with std::terminate, so using it unconditionally is probably a poor practice unless we plan to perform this exercise to look for std::terminate usage commonly. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
davidwrighton
marked this pull request as ready for review
September 29, 2026 18:19
jkoritzinsky
approved these changes
Sep 29, 2026
This was referenced Sep 29, 2026
Member
Author
|
/ba-g failure was a transient failure, which passed on rerun, but Build Analysis could not discover that it was fixed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add accurate
noexceptcontracts to non-throwing CoreCLR cleanup and synchronization paths, and compile CoreCLR WASM code with-fassume-nothrow-exception-dtor. Together, these let Clang remove C++ exception regions that only exist to callstd::terminate.The main affected paths are metadata enumeration and release, exception cleanup, GC mode restoration, thread-store locking, frame unwinding, PAL resource cleanup, executable allocation cleanup, and common holder traits.
The compiler flag is limited to actual CoreCLR Browser/WASI native compilation. Cross-component builds do not use it.
Browser/WASM results
Built the optimized Browser subset with:
dotnet.native.wasmstd::terminatesites-fassume-nothrow-exception-dtorlets Clang mark__cxa_end_catchas non-throwing. This removes the compiler-generated cleanup pads and terminate calls around exception-object destruction. The switch removes 1,053 terminate sites and 21,436 bytes beyond the source annotations alone. There are no explicitnoexcept(false)destructors undersrc/coreclrorsrc/native.Fourteen normalized functions gain 17 local terminate sites while removing 2,391 sites overall:
Frame::ExceptionUnwindgains two sites in centralized fail-fast/interpreter cleanup dispatch.UnmapViewOfFile,CloseHandle,SafeRelease,PEImage::Release, andExecutableAllocator::Releaseeach gain one site in a shared cleanup leaf.StringLiteralMap::GetInternedStringgains one shared cleanup site.LoaderHeap,GcInfoArrayListBase,GCHandleStore, andCLRExceptiondestructors each gain one. These are process-shutdown or cleanup paths.These are cleanup-only or shared leaf handlers and are outweighed by the caller-side removals reflected in the aggregate count and binary size.
Linux x64 validation
./build.sh clr+libs -rc Release -lc Release: passed with 0 warnings and 0 errors../build.sh clr -c Checked: passed with 0 warnings and 0 errors.cd src/tests && ./build.sh release: passed; 0 errors.cd src/tests && ./run.sh Release: 4,330 passed, 0 failed, 250 skipped.libcoreclr.so: 5,174,600 bytes baseline; 5,126,520 bytes changed; -48,080 bytes (-0.93%).A local BenchmarkDotNet baseline-vs-changed comparison found no significant regression and identical allocations:
Note
This pull request description was generated with GitHub Copilot.