Skip to content
Merged
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
14 changes: 14 additions & 0 deletions wasm/dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ Tests [.NET on WebAssembly](https://github.com/dotnet/runtime). This benchmark t
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)

## The Benchmark

Consists of two halves:

1) BenchTasks, which is a series of micro-benchmarks:
1) Exception throw/catch.
1) JSON serialization/deserialization.
1) String operations.

1) RayTracer

They run for different iterations/sizes, respectively for each half, depending on the variant (AOT/interpreter). The values to adjust the workloads are passed in from benchmark.js.


## Build instructions

Download .NET SDK 9.0.3xx
Expand Down
11 changes: 8 additions & 3 deletions wasm/dotnet/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,16 @@ class Benchmark {
this.api = await this.dotnet.withModuleConfig({ locateFile: e => e }).withConfig(config).create();
this.exports = await this.api.getAssemblyExports("dotnet.dll");


// This drives the workload size for BenchTasks half of the test.
this.benchTasksBatchSize = dotnetFlavor === "aot" ? 50 : 10;

// These drive the workload size for RayTrace half of the test.
this.hardwareConcurrency = 1;
this.sceneWidth = dotnetFlavor === "aot" ? 300 : 150;
this.sceneHeight = dotnetFlavor === "aot" ? 200 : 100;
this.sceneWidth = dotnetFlavor === "aot" ? 100 : 50;
this.sceneHeight = dotnetFlavor === "aot" ? 100 : 50;
}
async runIteration() {
await this.exports.Interop.RunIteration(this.sceneWidth, this.sceneHeight, this.hardwareConcurrency);
await this.exports.Interop.RunIteration(this.benchTasksBatchSize, this.sceneWidth, this.sceneHeight, this.hardwareConcurrency);
}
}
Binary file not shown.
Binary file modified wasm/dotnet/build-aot/wwwroot/_framework/System.Collections.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified wasm/dotnet/build-aot/wwwroot/_framework/System.Drawing.wasm
Binary file not shown.
Binary file not shown.
Binary file modified wasm/dotnet/build-aot/wwwroot/_framework/System.Linq.wasm
Binary file not shown.
Binary file modified wasm/dotnet/build-aot/wwwroot/_framework/System.Memory.wasm
Binary file not shown.
Binary file modified wasm/dotnet/build-aot/wwwroot/_framework/System.ObjectModel.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified wasm/dotnet/build-aot/wwwroot/_framework/System.Text.Json.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion wasm/dotnet/build-aot/wwwroot/_framework/dotnet.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion wasm/dotnet/build-aot/wwwroot/_framework/dotnet.native.js

Large diffs are not rendered by default.

42,239 changes: 21,119 additions & 21,120 deletions wasm/dotnet/build-aot/wwwroot/_framework/dotnet.native.js.symbols

Large diffs are not rendered by default.

Binary file modified wasm/dotnet/build-aot/wwwroot/_framework/dotnet.native.wasm
100644 → 100755
Binary file not shown.
2 changes: 1 addition & 1 deletion wasm/dotnet/build-aot/wwwroot/_framework/dotnet.runtime.js
100644 → 100755

Large diffs are not rendered by default.

Binary file modified wasm/dotnet/build-aot/wwwroot/_framework/dotnet.wasm
Binary file not shown.
Empty file modified wasm/dotnet/build-aot/wwwroot/_framework/icudt_CJK.dat
100644 → 100755
Empty file.
Empty file modified wasm/dotnet/build-aot/wwwroot/_framework/icudt_EFIGS.dat
100644 → 100755
Empty file.
Empty file modified wasm/dotnet/build-aot/wwwroot/_framework/icudt_no_CJK.dat
100644 → 100755
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified wasm/dotnet/build-interp/wwwroot/_framework/System.Drawing.wasm
Binary file not shown.
Binary file not shown.
Binary file modified wasm/dotnet/build-interp/wwwroot/_framework/System.Linq.wasm
Binary file not shown.
Binary file modified wasm/dotnet/build-interp/wwwroot/_framework/System.Memory.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion wasm/dotnet/build-interp/wwwroot/_framework/dotnet.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Binary file modified wasm/dotnet/build-interp/wwwroot/_framework/dotnet.native.wasm
100644 → 100755
Binary file not shown.
2 changes: 1 addition & 1 deletion wasm/dotnet/build-interp/wwwroot/_framework/dotnet.runtime.js
100644 → 100755

Large diffs are not rendered by default.

Binary file modified wasm/dotnet/build-interp/wwwroot/_framework/dotnet.wasm
Binary file not shown.
Empty file modified wasm/dotnet/build-interp/wwwroot/_framework/icudt_CJK.dat
100644 → 100755
Empty file.
Empty file modified wasm/dotnet/build-interp/wwwroot/_framework/icudt_EFIGS.dat
100644 → 100755
Empty file.
Empty file modified wasm/dotnet/build-interp/wwwroot/_framework/icudt_no_CJK.dat
100644 → 100755
Empty file.
8 changes: 8 additions & 0 deletions wasm/dotnet/build.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Built on 2025-08-27T15:57:18Z

Toolchain versions
9.0.304
Building interp...
Copying symbol maps...
Building aot...
Copying symbol maps...
24 changes: 21 additions & 3 deletions wasm/dotnet/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,30 @@

# Expects to have .NET SDK 9.0.3xx,
# downloadable from using https://aka.ms/dotnet/9.0.3xx/daily/dotnet-sdk-win-x64.zip or https://aka.ms/dotnet/9.0.3xx/daily/dotnet-sdk-linux-x64.tar.gz
# Then run (on macOS and probably Linux this requires sudo) idk how it works on Windows.
# `sudo dotnet workload install wasm-tools`

dotnet workload install wasm-tools
rm -r ./build-interp ./build-aot build.log

touch build.log
BUILD_LOG="$(realpath build.log)"

echo "Built on $(date -u '+%Y-%m-%dT%H:%M:%SZ')\n" | tee -a "$BUILD_LOG"
echo "Toolchain versions" | tee -a "$BUILD_LOG"
dotnet --version | tee -a "$BUILD_LOG"

echo "Building interp..." | tee -a "$BUILD_LOG"
dotnet publish -o ./build-interp ./src/dotnet/dotnet.csproj
printf '%s\n' 'import.meta.url ??= "";' | cat - ./build-interp/wwwroot/_framework/dotnet.js > temp.js && mv temp.js ./build-interp/wwwroot/_framework/dotnet.js

# Workaround for `jsc` CLI
printf '%s\n' 'import.meta.url ??= "";' | cat - ./src/dotnet/bin/Release/net9.0/wwwroot/_framework/dotnet.js > temp.js && mv temp.js ./build-interp/wwwroot/_framework/dotnet.js
echo "Copying symbol maps..." | tee -a "$BUILD_LOG"
cp ./src/dotnet/obj/Release/net9.0/wasm/for-publish/dotnet.native.js.symbols ./build-interp/wwwroot/_framework/

echo "Building aot..." | tee -a "$BUILD_LOG"
dotnet publish -o ./build-aot ./src/dotnet/dotnet.csproj -p:RunAOTCompilation=true

# Workaround for `jsc` CLI
printf '%s\n' 'import.meta.url ??= "";' | cat - ./build-aot/wwwroot/_framework/dotnet.js > temp.js && mv temp.js ./build-aot/wwwroot/_framework/dotnet.js
cp ./src/dotnet/obj/Release/net9.0/wasm/for-publish/dotnet.native.js.symbols ./build-aot/wwwroot/_framework/
echo "Copying symbol maps..." | tee -a "$BUILD_LOG"
cp ./src/dotnet/obj/Release/net9.0/wasm/for-publish/dotnet.native.js.symbols ./build-aot/wwwroot/_framework/
6 changes: 4 additions & 2 deletions wasm/dotnet/src/dotnet/Benchmarks/BenchTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.InteropServices.JavaScript;

public abstract class BenchTask
{
Expand All @@ -14,6 +15,7 @@ public abstract class BenchTask

public virtual bool BrowserOnly => false;

// FIXME: Deleting this breaks dotnet-interp with an out of memory error. No idea why...
public virtual int BatchSize => 100;

public async Task RunInitialSamples(int measurementIdx)
Expand All @@ -22,11 +24,11 @@ public async Task RunInitialSamples(int measurementIdx)
await measurement.RunInitialSamples();
}

public async Task RunBatch(int measurementIdx)
public async Task RunBatch(int measurementIdx, int batchSize)
{
var measurement = Measurements[measurementIdx];
await measurement.BeforeBatch();
await measurement.RunBatch(BatchSize);
await measurement.RunBatch(batchSize);
await measurement.AfterBatch();
}

Expand Down
4 changes: 2 additions & 2 deletions wasm/dotnet/src/dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ static partial class Interop
];

[JSExport]
public static async Task RunIteration(int sceneWidth, int sceneHeight, int hardwareConcurrency)
public static async Task RunIteration(int benchTasksBatchSize, int sceneWidth, int sceneHeight, int hardwareConcurrency)
{
// BenchTasks
for (int i = 0; i < tasks.Length; i++)
{
var task = tasks[i];
for (int j = 0; j < task.Measurements.Length; j++)
{
await task.RunBatch(i);
await task.RunBatch(i, benchTasksBatchSize);
}
}

Expand Down
Loading