Skip to content

Add support for the new WASM Exception Handling feature - #66435

Merged
vargaz merged 6 commits into
dotnet:mainfrom
vargaz:wasm-eh
Mar 11, 2022
Merged

Add support for the new WASM Exception Handling feature#66435
vargaz merged 6 commits into
dotnet:mainfrom
vargaz:wasm-eh

Conversation

@vargaz

Copy link
Copy Markdown
Contributor

No description provided.

vargaz added 2 commits March 9, 2022 23:53
WASM EH uses the newly added llvm catchpad instructions instead of
the old landingpad instructions. Add a --wasm-exceptions option
to control whenever the old JS style or the new WASM style code
is generated.
@ghostghost assigned vargazMar 10, 2022
@ghostghost added the area-Build-mono label Mar 10, 2022
@vargaz
vargaz requested review from kg, radekdoulik and radical and removed request for SamMonoRT, lambdageek and marek-safarMarch 10, 2022 05:04
Comment threadsrc/mono/CMakeLists.txt Outdated
@vargaz

Copy link
Copy Markdown
ContributorAuthor

Benchmarks:
BEFORE:


.md
| measurement | time |
|-:|-:|
| Exceptions, NoExceptionHandling | 0.0761us |
| Exceptions, TryCatch | 0.1133us |
| Exceptions, TryCatchThrow | 0.0162ms |
| Exceptions, TryCatchFilter | 0.1101us |
| Exceptions, TryCatchFilterInline | 0.0824us |
| Exceptions, TryCatchFilterThrow | 0.0270ms |
| Exceptions, TryCatchFilterThrowApplies | 0.0225ms |
| Json, non-ASCII text serialize | 1.2152ms |
| Json, non-ASCII text deserialize | 2.2020ms |
| Json, small serialize | 0.1147ms |
| Json, small deserialize | 0.1594ms |
| Json, large serialize | 22.4554ms |
| Json, large deserialize | 46.6294ms |

AFTER:

.md
| measurement | time |
|-:|-:|
| Exceptions, NoExceptionHandling | 0.0222us |
| Exceptions, TryCatch | 0.0383us |
| Exceptions, TryCatchThrow | 0.0760ms |
| Exceptions, TryCatchFilter | 0.0389us |
| Exceptions, TryCatchFilterInline | 0.0379us |
| Exceptions, TryCatchFilterThrow | 0.0865ms |
| Exceptions, TryCatchFilterThrowApplies | 0.0819ms |
| Json, non-ASCII text serialize | 1.3284ms |
| Json, non-ASCII text deserialize | 2.5833ms |
| Json, small serialize | 0.0931ms |
| Json, small deserialize | 0.1310ms |
| Json, large serialize | 21.0037ms |
| Json, large deserialize | 37.7421ms |

A micro benchmark which iterated on an IEnumerable got about 60% faster.

Comment threadsrc/mono/mono/mini/CMakeLists.txt Outdated

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.

💃🎉🎊🥳

Comment threadsrc/mono/mono/mini/mini-llvm.c Outdated
Comment threadsrc/mono/wasm/build/WasmApp.Native.targets Outdated
It is controlled by the $(WasmExceptionHandling) msbuild property.
Its only used in AOT mode, the interpreter mode wouldn't benefit from it.
The only file in the runtime which contains a throw or a catch is
llvm-runtime.cpp, so create 2 small static libraries from this file:
* libmono-wasm-eh-js - compiled to use JS style EH
* libmono-wasm-eh-wasm - compiled to use WASM style EH
This avoids the need to compile 2 versions of the whole runtime.
Requires emscripten 3.x.

@radekdoulikradekdoulik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM


if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_custom_command(TARGET dotnet POST_BUILD COMMAND ${EMSDK_PATH}/upstream/bin/wasm-opt --strip-dwarf ${NATIVE_BIN_DIR}/dotnet.wasm -o ${NATIVE_BIN_DIR}/dotnet.wasm)
add_custom_command(TARGET dotnet POST_BUILD COMMAND ${EMSDK_PATH}/upstream/bin/wasm-opt --enable-exception-handling --strip-dwarf ${NATIVE_BIN_DIR}/dotnet.wasm -o ${NATIVE_BIN_DIR}/dotnet.wasm)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does --enable-exception-handling do something also for wasm-eh-js case?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Its needed for wasm-opt to not fail, it looks harmless otherwise.

@radekdoulik

Copy link
Copy Markdown
Member

The measurements look nice! One thing I wonder about is why the throw cases are now slower. Do you know what might be behind this? Maybe this path is not just optimized yet in v8?

@radekdoulik

Copy link
Copy Markdown
Member

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Comment threadsrc/mono/mono/mini/CMakeLists.txt
Comment threadsrc/mono/CMakeLists.txt Outdated
@SamMonoRT

Copy link
Copy Markdown
Member

Contributes to #63399

Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
@vargaz

Copy link
Copy Markdown
ContributorAuthor

/azp run runtime-wasm

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

<_EmccCommonFlags Include="-s EXPORT_ES6=1" Condition="'$(WasmEnableES6)' == 'true'" />
<_EmccCommonFlags Include="-g" Condition="'$(WasmNativeStrip)' == 'false'" />
<_EmccCommonFlags Include="-v" Condition="'$(EmccVerbose)' != 'false'" />
<_EmccCommonFlags Include="-s DISABLE_EXCEPTION_CATCHING=0" Condition="'$(WasmExceptionHandling)' == 'false'" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
<_EmccCommonFlagsInclude="-s DISABLE_EXCEPTION_CATCHING=0"Condition="'$(WasmExceptionHandling)' == 'false'" />
<_EmccCommonFlagsInclude="-s DISABLE_EXCEPTION_CATCHING=0"Condition="'$(WasmExceptionHandling)' != 'true'" />

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Why is this needed ? The property is initialized to false if not set.

 <WasmExceptionHandling Condition="'$(WasmExceptionHandling)' == ''">false</WasmExceptionHandling>

- $(RunAOTCompilationAfterBuild) - Run AOT compilation even after Build. By default, it is run only for publish.
Defaults to false.
- $(WasmAotProfilePath) - Path to an AOT profile file.
- $(WasmExceptionHandling) - Enable support for the WASM Exception Handling feature.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be renamed to WasmEnableExceptionHandling.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

that sounds like there wouldn't be exception handling support if it isn't true though

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

WasmEnableWasmEHFeature? WasmEnableNativeExceptionHandlingFeature?

@vargaz

Copy link
Copy Markdown
ContributorAuthor

The CI failures look unrelated

@vargaz

Copy link
Copy Markdown
ContributorAuthor

Will merge this for now, the property can be renamed later.

@vargaz
vargaz merged commit 3e2d483 into dotnet:mainMar 11, 2022
@vargaz
vargaz deleted the wasm-eh branch March 11, 2022 16:50
@ghostghost locked as resolved and limited conversation to collaborators Apr 10, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@vargaz@radekdoulik@SamMonoRT@radical@lewing@kg@lambdageek@akoeplinger