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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 47 additions & 0 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,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({
Expand Down Expand Up @@ -2235,6 +2261,27 @@ let BENCHMARKS = [
iterations: 40,
tags: ["Wasm"],
}),
// .NET
new AsyncBenchmark({
name: "dotnet-interp",
files: [
"./wasm/dotnet/benchmark.js",
],
preload: dotnetPreloads("interp"),
iterations: 2,
worstCaseCount: 1,
tags: ["Wasm", "dotnet"]
}),
new AsyncBenchmark({
name: "dotnet-aot",
files: [
"./wasm/dotnet/benchmark.js",
],
preload: dotnetPreloads("aot"),
iterations: 4,
worstCaseCount: 1,
tags: ["Wasm", "dotnet"]
})
];

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

<dt id="dotnet-interp-string">dotnet-interp-string</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-string">dotnet-aot-string</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>
Expand Down
5 changes: 5 additions & 0 deletions wasm/dotnet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.binlog
.dotnet
.nuget
bin
obj
137 changes: 137 additions & 0 deletions wasm/dotnet/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
class Benchmark {
async init() {
async function fetchBin(name) {
return new Uint8Array(await (await fetch(name)).arrayBuffer());
}

const config = {
mainAssemblyName: "dotnet.dll",
globalizationMode: "custom",
assets: [
{
name: "dotnet.runtime.js",
resolvedUrl: dotnetRuntimeUrl,
moduleExports: await import(dotnetRuntimeUrl),
behavior: "js-module-runtime"
},
{
name: "dotnet.native.js",
resolvedUrl: dotnetNativeUrl,
moduleExports: await import(dotnetNativeUrl),
behavior: "js-module-native"
},
{
name: "dotnet.native.wasm",
resolvedUrl: wasmBinaryUrl,
buffer: await fetchBin(wasmBinaryUrl),
behavior: "dotnetwasm"
},
{
name: "icudt_CJK.dat",
resolvedUrl: icuCustomUrl,
buffer: await fetchBin(icuCustomUrl),
behavior: "icu"
},
{
name: "System.Collections.Concurrent.wasm",
resolvedUrl: dllCollectionsConcurrentUrl,
buffer: await fetchBin(dllCollectionsConcurrentUrl),
behavior: "assembly"
},
{
name: "System.Collections.wasm",
resolvedUrl: dllCollectionsUrl,
buffer: await fetchBin(dllCollectionsUrl),
behavior: "assembly"
},
{
name: "System.ComponentModel.Primitives.wasm",
resolvedUrl: dllComponentModelPrimitivesUrl,
buffer: await fetchBin(dllComponentModelPrimitivesUrl),
behavior: "assembly"
},
{
name: "System.ComponentModel.TypeConverter.wasm",
resolvedUrl: dllComponentModelTypeConverterUrl,
buffer: await fetchBin(dllComponentModelTypeConverterUrl),
behavior: "assembly"
},
{
name: "System.Drawing.Primitives.wasm",
resolvedUrl: dllDrawingPrimitivesUrl,
buffer: await fetchBin(dllDrawingPrimitivesUrl),
behavior: "assembly"
},
{
name: "System.Drawing.wasm",
resolvedUrl: dllDrawingUrl,
buffer: await fetchBin(dllDrawingUrl),
behavior: "assembly"
},
{
name: "System.IO.Pipelines.wasm",
resolvedUrl: dllIOPipelinesUrl,
buffer: await fetchBin(dllIOPipelinesUrl),
behavior: "assembly"
},
{
name: "System.Linq.wasm",
resolvedUrl: dllLinqUrl,
buffer: await fetchBin(dllLinqUrl),
behavior: "assembly"
},
{
name: "System.Memory.wasm",
resolvedUrl: dllMemoryUrl,
buffer: await fetchBin(dllMemoryUrl),
behavior: "assembly"
},
{
name: "System.ObjectModel.wasm",
resolvedUrl: dllObjectModelUrl,
buffer: await fetchBin(dllObjectModelUrl),
behavior: "assembly"
},
{
name: "System.Private.CoreLib.wasm",
resolvedUrl: dllPrivateCorelibUrl,
buffer: await fetchBin(dllPrivateCorelibUrl),
behavior: "assembly"
},
{
name: "System.Runtime.InteropServices.JavaScript.wasm",
resolvedUrl: dllRuntimeInteropServicesJavaScriptUrl,
buffer: await fetchBin(dllRuntimeInteropServicesJavaScriptUrl),
behavior: "assembly"
},
{
name: "System.Text.Encodings.Web.wasm",
resolvedUrl: dllTextEncodingsWebUrl,
buffer: await fetchBin(dllTextEncodingsWebUrl),
behavior: "assembly"
},
{
name: "System.Text.Json.wasm",
resolvedUrl: dllTextJsonUrl,
buffer: await fetchBin(dllTextJsonUrl),
behavior: "assembly"
},
{
name: "dotnet.wasm",
resolvedUrl: dllAppUrl,
buffer: await fetchBin(dllAppUrl),
behavior: "assembly"
}
]
};

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

await this.exports.Interop.WarmUp(320, 240, globalThis.navigator.hardwareConcurrency);
}
async runIteration() {
await this.exports.Interop.RunIteration();
}
}
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.
4 changes: 4 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.

Binary file not shown.
4 changes: 4 additions & 0 deletions wasm/dotnet/build-aot/wwwroot/_framework/dotnet.runtime.js

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
44 changes: 44 additions & 0 deletions wasm/dotnet/build-interp/web.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".blat" />
<remove fileExtension=".dat" />
<remove fileExtension=".dll" />
<remove fileExtension=".webcil" />
<remove fileExtension=".json" />
<remove fileExtension=".wasm" />
<remove fileExtension=".woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".blat" mimeType="application/octet-stream" />
<mimeMap fileExtension=".dll" mimeType="application/octet-stream" />
<mimeMap fileExtension=".webcil" mimeType="application/octet-stream" />
<mimeMap fileExtension=".dat" mimeType="application/octet-stream" />
<mimeMap fileExtension=".json" mimeType="application/json" />
<mimeMap fileExtension=".wasm" mimeType="application/wasm" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
</staticContent>
<httpCompression>
<dynamicTypes>
<add mimeType="application/octet-stream" enabled="true" />
<add mimeType="application/wasm" enabled="true" />
</dynamicTypes>
</httpCompression>
<rewrite>
<rules>
<rule name="Serve subdir">
<match url=".*" />
<action type="Rewrite" url="wwwroot\{R:0}" />
</rule>
<rule name="SPA fallback routing" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="wwwroot\" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
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.
4 changes: 4 additions & 0 deletions wasm/dotnet/build-interp/wwwroot/_framework/dotnet.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Binary file not shown.
4 changes: 4 additions & 0 deletions wasm/dotnet/build-interp/wwwroot/_framework/dotnet.runtime.js

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions wasm/dotnet/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Download .NET SDK 9.0.300
# Install workload wasm-tools
dotnet publish -o ./build-interp ./src/dotnet/dotnet.csproj
dotnet publish -o ./build-aot ./src/dotnet/dotnet.csproj -p:RunAOTCompilation=true
Loading