Skip to content

[NativeAOT-LLVM] Exclude ExceptionHandling.cs from the WASM build and pass -O1 to emcc #3133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: feature/NativeAOT-LLVM
Choose a base branch
from

Conversation

SingleAccretion
Copy link

@SingleAccretion SingleAccretion commented Jul 12, 2025

The non-WASM EH code roots almost 0.8% of HelloWorld code.

Diffs (WasmDebugging):

Summary of Code Size diffs:
(Lower is better)

Total bytes of base: 674872
Total bytes of diff: 669465
Total bytes of delta: -5407 (-0.80% % of base)
Average relative delta: 2.13%
    diff is an improvement
    average relative diff is a regression

Top method regressions (percentages):
         933 (134.05% of base) : 1049.dasm - S_P_CoreLib_System_Exception__ToString
         128 (54.94% of base) : 1031.dasm - S_P_CoreLib_System_Runtime_InteropServices_GCHandle___ctor
         140 (45.16% of base) : 1007.dasm - S_P_CoreLib_System_Runtime_RuntimeExports__RhUnboxAny
         119 (16.39% of base) : 1029.dasm - S_P_CoreLib_Internal_TypeSystem_LockFreeReaderHashtableOfPointers_2<S_P_CoreLib_Internal_Runtime_IDynamicCastableSupport_InstantiatingThunkKey__IntPtr>__Expand
         119 (15.78% of base) : 1028.dasm - S_P_CoreLib_Internal_TypeSystem_LockFreeReaderHashtableOfPointers_2<S_P_CoreLib_Internal_Runtime_IDynamicCastableSupport_InstantiatingThunkKey__IntPtr>__TryAddOrGetExisting
          15 ( 2.38% of base) : 1050.dasm - S_P_CoreLib_System_Runtime_TypeCast__AreTypesAssignableInternalUncached

Top method improvements (percentages):
        -185 (-81.14% of base) : 1030.dasm - S_P_CoreLib_System_Runtime_CachedInterfaceDispatch__RhpCidResolve
        -122 (-37.54% of base) : 1048.dasm - S_P_CoreLib_System_Runtime_TypeCast__AreTypesAssignable
        -198 (-21.45% of base) : 1038.dasm - S_P_CoreLib_System_Runtime_EH__DispatchException
        -119 (-17.73% of base) : 1047.dasm - S_P_CoreLib_Internal_Runtime_IDynamicCastableSupport__IDynamicCastableGetInterfaceImplementation
          -2 (-1.22% of base) : 1046.dasm - S_P_CoreLib_System_Runtime_DispatchResolve__FindImplSlotForCurrentType
          -5 (-0.95% of base) : 1008.dasm - S_P_CoreLib_Internal_Runtime_CompilerHelpers_StartupCodeHelpers__CreateTypeManagers

Top methods only present in base:
        -789 (-100.00% of base) : 1036.dasm - S_P_CoreLib_System_Runtime_EH__DispatchEx
        -715 (-100.00% of base) : 1012.dasm - StackFrameIterator::NextInternal()
        -657 (-100.00% of base) : 1042.dasm - S_P_CoreLib_System_Runtime_EH__FindFirstPassHandler
        -501 (-100.00% of base) : 1039.dasm - S_P_CoreLib_System_Runtime_EH__InvokeSecondPass_0
        -415 (-100.00% of base) : 1040.dasm - S_P_CoreLib_System_Runtime_EH__UnhandledExceptionFailFastViaClasslib
        -392 (-100.00% of base) : 1010.dasm - StackFrameIterator::InternalInitForStackTrace()
        -370 (-100.00% of base) : 1025.dasm - S_P_CoreLib_System_Runtime_EH__RhThrowHwEx
        -336 (-100.00% of base) : 1034.dasm - S_P_CoreLib_System_Runtime_EH__FailFastViaClasslib
        -333 (-100.00% of base) : 1044.dasm - S_P_CoreLib_System_Runtime_EH__AppendExceptionStackFrameViaClasslib
        -280 (-100.00% of base) : 1033.dasm - S_P_CoreLib_System_Runtime_EH__GetClasslibException
        -258 (-100.00% of base) : 1009.dasm - StackFrameIterator::CalculateCurrentMethodState()
        -211 (-100.00% of base) : 1015.dasm - RhpSfiNext
        -155 (-100.00% of base) : 1014.dasm - RhpSfiInit
        -134 (-100.00% of base) : 1024.dasm - S_P_CoreLib_System_Runtime_EH__RhThrowEx
        -115 (-100.00% of base) : 1021.dasm - S_P_CoreLib_System_Runtime_EH__RhpFailFastForPInvokeExceptionPreemp
        -110 (-100.00% of base) : 1023.dasm - S_P_CoreLib_System_Runtime_EH__RhRethrow
         -78 (-100.00% of base) : 1032.dasm - S_P_CoreLib_System_Runtime_EH_ExInfo__Init
         -65 (-100.00% of base) : 1016.dasm - RhpEHEnumInitFromStackFrameIterator
         -60 (-100.00% of base) : 1000.dasm - RuntimeInstance::GetClasslibFunctionFromCodeAddress(void*, ClasslibFunctionId)
         -44 (-100.00% of base) : 1019.dasm - RhpSetThreadDoNotTriggerGC

51 total methods with Code Size differences (45 improved, 6 regressed)

The -O1 change excises yet more code by making Emscripten link-in the "release" version of its standard libraries.

Summary of Code Size diffs:
(Lower is better)

Total bytes of base: 669465
Total bytes of diff: 659909
Total bytes of delta: -9556 (-1.43% % of base)
Average relative delta: -2.81%
    diff is an improvement
    average relative diff is an improvement

Top method improvements (percentages):
         -78 (-89.66% of base) : 1030.dasm - abort_message
          -3 (-11.54% of base) : 1000.dasm - __wasm_call_ctors

Top methods only present in base:
       -3376 (-100.00% of base) : 1020.dasm - fmt_fp
       -2548 (-100.00% of base) : 1011.dasm - printf_core
        -570 (-100.00% of base) : 1014.dasm - pop_arg
        -504 (-100.00% of base) : 1009.dasm - __trunctfdf2
        -403 (-100.00% of base) : 1010.dasm - __vfprintf_internal
        -300 (-100.00% of base) : 1004.dasm - wcrtomb
        -229 (-100.00% of base) : 1002.dasm - memchr
        -164 (-100.00% of base) : 1023.dasm - __overflow
        -146 (-100.00% of base) : 1006.dasm - frexp
        -136 (-100.00% of base) : 1017.dasm - fmt_u
        -132 (-100.00% of base) : 1026.dasm - locking_putc
        -132 (-100.00% of base) : 1018.dasm - pad
        -123 (-100.00% of base) : 1025.dasm - do_putc
        -123 (-100.00% of base) : 1013.dasm - getint
         -83 (-100.00% of base) : 1007.dasm - __ashlti3
         -83 (-100.00% of base) : 1008.dasm - __lshrti3
         -64 (-100.00% of base) : 1015.dasm - fmt_x
         -54 (-100.00% of base) : 1016.dasm - fmt_o
         -49 (-100.00% of base) : 1021.dasm - pop_arg_long_double
         -32 (-100.00% of base) : 1031.dasm - emscripten_stack_init

36 total methods with Code Size differences (36 improved, 0 regressed)

Contributes to #3132.
Contributes to #2169.

@SingleAccretion SingleAccretion marked this pull request as ready for review July 12, 2025 20:32
@SingleAccretion
Copy link
Author

@dotnet/nativeaot-llvm

This both avoids wasm-opt and makes emscripten link-in the optimized
version of its standard library, saving ~1.5% in code size for WasmDebugging.
@SingleAccretion SingleAccretion changed the title [NativeAOT-LLVM] Exclude ExceptionHandling.cs from the WASM build [NativeAOT-LLVM] Exclude ExceptionHandling.cs from the WASM build and pass -O1 to emcc Jul 12, 2025
@jkotas jkotas added the area-NativeAOT-LLVM LLVM generation for Native AOT compilation (including Web Assembly) label Jul 13, 2025
Copy link
Contributor

@yowl yowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-LLVM LLVM generation for Native AOT compilation (including Web Assembly)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants