Skip to content
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

[Wasm][AOT] Methods containing a try/catch block are 30x slower because of the interpreter #56309

Closed
jeromelaban opened this issue Jul 26, 2021 · 8 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-Codegen-AOT-mono
Milestone

Comments

@jeromelaban
Copy link
Contributor

jeromelaban commented Jul 26, 2021

Description

Methods containing a try/catch/finally are 30x slower in recent builds because they are now run through the interpreter.

For example:

private static void TestTryCatch()
{
	int InvokeMethod(int a)
	{
		try
		{
			return a++;
		}
		catch
		{
			Console.WriteLine("catch");
			return 0;
		}
	}

	var sw = Stopwatch.StartNew();
	for (int i = 0; i < 10000000; i++)
	{
		InvokeMethod(i);
	}
	sw.Stop();
	Console.WriteLine($"TestTryCatch: {sw.ElapsedMilliseconds}");
}

Runs in 45ms with df6e956, and 1140ms with e983168

Here's a profiler trace screenshot:

image

Configuration

Working commit: df6e956
Failing commit: e983168 (it probably started doing this before this commit)

Regression?

Yes

Other information

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Jul 26, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

jeromelaban added a commit to jeromelaban/Wasm.Samples that referenced this issue Jul 26, 2021
@radical radical added arch-wasm WebAssembly architecture area-Codegen-AOT-mono labels Jul 26, 2021
@ghost
Copy link

ghost commented Jul 26, 2021

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Methods containing a try/catch/finally are 30x slower in recent builds because they are now run through the interpreter.

For example:

private static void TestTryCatch()
{
	int InvokeMethod(int a)
	{
		try
		{
			return a++;
		}
		catch
		{
			Console.WriteLine("catch");
			return 0;
		}
	}

	var sw = Stopwatch.StartNew();
	for (int i = 0; i < 10000000; i++)
	{
		InvokeMethod(i);
	}
	sw.Stop();
	Console.WriteLine($"TestTryCatch: {sw.ElapsedMilliseconds}");
}

Runs in 45ms with df6e956, and 1140ms with e983168

Here's a profiler trace screenshot:

image

Configuration

Working commit: df6e956
Failing commit: e983168 (it probably started doing this before this commit)

Regression?

Yes

Other information

Author: jeromelaban
Assignees: -
Labels:

arch-wasm, area-Codegen-AOT-mono, untriaged

Milestone: -

@jeromelaban
Copy link
Contributor Author

Related to #53815 and #52883

@lewing lewing added this to the 6.0.0 milestone Jul 26, 2021
@lewing lewing removed the untriaged New issue has not been triaged by the area owner label Jul 26, 2021
@jeromelaban
Copy link
Contributor Author

Applying this patch to the runtime reverts original behavior, knowing that the original exception handling scenario will be a problem.

@roonius
Copy link

roonius commented Sep 14, 2021

@jeromelaban , when exactly was this change introduced? What is the max version before this change? Thanks.

@jeromelaban
Copy link
Contributor Author

@roonius there is no stable version of the runtime that does not have this change. Each interim build had a different set of issues, and removing the interpreter restriction causes failures when handling exceptions, which is why the restriction is present in Uno.Wasm.Bootstrap builds of the runtime.

@vargaz
Copy link
Contributor

vargaz commented Jan 3, 2022

With this PR: #63065
methods which contain only finally/fault clauses (foreach, iterators, etc.) will be AOTed.

@vargaz
Copy link
Contributor

vargaz commented Mar 16, 2022

This is fixed now.

@vargaz vargaz closed this as completed Mar 16, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Apr 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Codegen-AOT-mono
Projects
None yet
Development

No branches or pull requests

5 participants