Skip to content

Add .NET on WebAssembly workload #73

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

Merged
merged 28 commits into from
Jul 23, 2025
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
@@ -1543,6 +1543,32 @@ class WasmLegacyBenchmark extends Benchmark {
}
};

function dotnetPreloads(type)
{
return {
dotnetUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/dotnet.js`,
dotnetNativeUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/dotnet.native.js`,
dotnetRuntimeUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/dotnet.runtime.js`,
wasmBinaryUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/dotnet.native.wasm`,
icuCustomUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/icudt_CJK.dat`,
dllCollectionsConcurrentUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Collections.Concurrent.wasm`,
dllCollectionsUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Collections.wasm`,
dllComponentModelPrimitivesUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.ComponentModel.Primitives.wasm`,
dllComponentModelTypeConverterUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.ComponentModel.TypeConverter.wasm`,
dllDrawingPrimitivesUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Drawing.Primitives.wasm`,
dllDrawingUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Drawing.wasm`,
dllIOPipelinesUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.IO.Pipelines.wasm`,
dllLinqUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Linq.wasm`,
dllMemoryUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Memory.wasm`,
dllObjectModelUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.ObjectModel.wasm`,
dllPrivateCorelibUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Private.CoreLib.wasm`,
dllRuntimeInteropServicesJavaScriptUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Runtime.InteropServices.JavaScript.wasm`,
dllTextEncodingsWebUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Text.Encodings.Web.wasm`,
dllTextJsonUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/System.Text.Json.wasm`,
dllAppUrl: `./wasm/dotnet/build-${type}/wwwroot/_framework/dotnet.wasm`,
}
}

let BENCHMARKS = [
// ARES
new DefaultBenchmark({
@@ -2248,6 +2274,29 @@ let BENCHMARKS = [
iterations: 40,
tags: ["Wasm"],
}),
// .NET
new AsyncBenchmark({
name: "dotnet-interp",
files: [
"./wasm/dotnet/interp.js",
"./wasm/dotnet/benchmark.js",
],
preload: dotnetPreloads("interp"),
iterations: 10,
worstCaseCount: 2,
tags: ["Wasm", "dotnet"]
}),
new AsyncBenchmark({
name: "dotnet-aot",
files: [
"./wasm/dotnet/aot.js",
"./wasm/dotnet/benchmark.js",
],
preload: dotnetPreloads("aot"),
iterations: 15,
worstCaseCount: 2,
tags: ["Wasm", "dotnet"]
})
];

// LuaJSFight tests
14 changes: 14 additions & 0 deletions in-depth.html
Original file line number Diff line number Diff line change
@@ -776,6 +776,20 @@ <h3>
Source code: <a href="proxy/vue-benchmark.js">vue-benchmark.js</a>
</dd>

<dt id="dotnet-interp">dotnet-interp</dt>
<dd>
Tests <a href="https://github.com/dotnet/runtime">.NET on WebAssembly</a>. This benchmark tests operations
on .NET implementation of String, JSON serialization, specifics of .NET exceptions and computation
of a 3D scene using Mono Interpreter. Source code: <a href="wasm/dotnet">.NET</a>.
</dd>

<dt id="dotnet-aot">dotnet-aot</dt>
<dd>
Tests <a href="https://github.com/dotnet/runtime">.NET on WebAssembly</a>. This benchmark tests operations
on .NET implementation of String, JSON serialization, specifics of .NET exceptions and computation
of a 3D scene using Mono AOT. Source code: <a href="wasm/dotnet">.NET</a>.
</dd>

</dl>

<p><a href="index.html" class="button">&larr; Return to Tests</a></p>
8 changes: 8 additions & 0 deletions wasm/dotnet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.binlog
.dotnet
.nuget
bin
obj
blazor.boot.json
web.config
*.staticwebassets.endpoints.json
30 changes: 30 additions & 0 deletions wasm/dotnet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# .NET on WebAssembly

Tests [.NET on WebAssembly](https://github.com/dotnet/runtime). This benchmark tests operations
on .NET implementation of String, JSON serialization, specifics of .NET exceptions and computation
of a 3D scene using Mono Interpreter & AOT. Source code: [.NET](wasm/dotnet)

## Build instructions

Download .NET SDK 9.0.3xx

- [dotnet-sdk-win-x64.zip](https://aka.ms/dotnet/9.0.3xx/daily/dotnet-sdk-win-x64.zip)
- [dotnet-sdk-linux-x64.tar.gz](https://aka.ms/dotnet/9.0.3xx/daily/dotnet-sdk-linux-x64.tar.gz)

Run `build.sh` script. It will install `wasm-tools` workload & build the benchmark code twice (for Mono interpreter & AOT).

To run the benchmark code on `jsc`, we are prepending `import.meta.url ??= ""` to `dotnet.js`.

## Background on .NET / build output files

Mono AOT works in a "mixed mode". It is not able to compile all code patterns and in various scenarios it falls back to interpreter.
Because of that we are still loading managed dlls (all the other not-`dotnet.native.wasm` files).

Structure of the build output

- `dotnet.js` is entrypoint JavaScript with public API.
- `dotnet.runtime.js` is internal implementation of JavaScript logic for .NET.
- `dotnet.native.js` is emscripten module configured for .NET.
- `dotnet.native.wasm` is unmanaged code (Mono runtime + AOT compiled code).
- `System.*.wasm` is .NET BCL that has unused code trimmed away.
- `dotnet.wasm` is the benchmark code.
1 change: 1 addition & 0 deletions wasm/dotnet/aot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
globalThis.dotnetFlavor = "aot";
138 changes: 138 additions & 0 deletions wasm/dotnet/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
class Benchmark {
async init() {
const config = {
mainAssemblyName: "dotnet.dll",
globalizationMode: "custom",
assets: [
{
name: "dotnet.runtime.js",
resolvedUrl: dotnetRuntimeUrl,
moduleExports: await dynamicImport(dotnetRuntimeUrl),
behavior: "js-module-runtime"
},
{
name: "dotnet.native.js",
resolvedUrl: dotnetNativeUrl,
moduleExports: await dynamicImport(dotnetNativeUrl),
behavior: "js-module-native"
},
{
name: "dotnet.native.wasm",
resolvedUrl: wasmBinaryUrl,
buffer: await getBinary(wasmBinaryUrl),
behavior: "dotnetwasm"
},
{
name: "icudt_CJK.dat",
resolvedUrl: icuCustomUrl,
buffer: await getBinary(icuCustomUrl),
behavior: "icu"
},
{
name: "System.Collections.Concurrent.wasm",
resolvedUrl: dllCollectionsConcurrentUrl,
buffer: await getBinary(dllCollectionsConcurrentUrl),
behavior: "assembly"
},
{
name: "System.Collections.wasm",
resolvedUrl: dllCollectionsUrl,
buffer: await getBinary(dllCollectionsUrl),
behavior: "assembly"
},
{
name: "System.ComponentModel.Primitives.wasm",
resolvedUrl: dllComponentModelPrimitivesUrl,
buffer: await getBinary(dllComponentModelPrimitivesUrl),
behavior: "assembly"
},
{
name: "System.ComponentModel.TypeConverter.wasm",
resolvedUrl: dllComponentModelTypeConverterUrl,
buffer: await getBinary(dllComponentModelTypeConverterUrl),
behavior: "assembly"
},
{
name: "System.Drawing.Primitives.wasm",
resolvedUrl: dllDrawingPrimitivesUrl,
buffer: await getBinary(dllDrawingPrimitivesUrl),
behavior: "assembly"
},
{
name: "System.Drawing.wasm",
resolvedUrl: dllDrawingUrl,
buffer: await getBinary(dllDrawingUrl),
behavior: "assembly"
},
{
name: "System.IO.Pipelines.wasm",
resolvedUrl: dllIOPipelinesUrl,
buffer: await getBinary(dllIOPipelinesUrl),
behavior: "assembly"
},
{
name: "System.Linq.wasm",
resolvedUrl: dllLinqUrl,
buffer: await getBinary(dllLinqUrl),
behavior: "assembly"
},
{
name: "System.Memory.wasm",
resolvedUrl: dllMemoryUrl,
buffer: await getBinary(dllMemoryUrl),
behavior: "assembly"
},
{
name: "System.ObjectModel.wasm",
resolvedUrl: dllObjectModelUrl,
buffer: await getBinary(dllObjectModelUrl),
behavior: "assembly"
},
{
name: "System.Private.CoreLib.wasm",
resolvedUrl: dllPrivateCorelibUrl,
buffer: await getBinary(dllPrivateCorelibUrl),
behavior: "assembly",
isCore: true
},
{
name: "System.Runtime.InteropServices.JavaScript.wasm",
resolvedUrl: dllRuntimeInteropServicesJavaScriptUrl,
buffer: await getBinary(dllRuntimeInteropServicesJavaScriptUrl),
behavior: "assembly",
isCore: true
},
{
name: "System.Text.Encodings.Web.wasm",
resolvedUrl: dllTextEncodingsWebUrl,
buffer: await getBinary(dllTextEncodingsWebUrl),
behavior: "assembly"
},
{
name: "System.Text.Json.wasm",
resolvedUrl: dllTextJsonUrl,
buffer: await getBinary(dllTextJsonUrl),
behavior: "assembly"
},
{
name: "dotnet.wasm",
resolvedUrl: dllAppUrl,
buffer: await getBinary(dllAppUrl),
behavior: "assembly",
isCore: true
}
]
};

this.dotnet = (await dynamicImport(dotnetUrl)).dotnet;
this.api = await this.dotnet.withModuleConfig({ locateFile: e => e }).withConfig(config).create();
this.exports = await this.api.getAssemblyExports("dotnet.dll");

this.hardwareConcurrency = 1;
this.sceneWidth = dotnetFlavor === "aot" ? 300 : 150;
this.sceneHeight = dotnetFlavor === "aot" ? 200 : 100;
}
async runIteration() {
await this.exports.Interop.RunIteration(this.sceneWidth, this.sceneHeight, this.hardwareConcurrency);
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions wasm/dotnet/build-aot/wwwroot/_framework/dotnet.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions wasm/dotnet/build-aot/wwwroot/_framework/dotnet.native.js

Large diffs are not rendered by default.

Loading