Skip to content

Commit 06fb856

Browse files
authored
[wasm] browser-bench improvements (#59028)
Do not supress all linker warnings. Use UnconditionalSuppressMessage attribute to supress these we know are ok. Add new WebSocketTask to the default tasks array. Enable disabled exception measurements as they don't crash anymore. Improve summary output. Example output: | measurement | time | |-:|-:| | Exceptions, NoExceptionHandling | 0.2288us | | Exceptions, TryCatch | 0.2480us | | Exceptions, TryCatchThrow | 0.0083ms | | Exceptions, TryCatchFilter | 0.1917us | | Exceptions, TryCatchFilterInline | 0.0486us | | Exceptions, TryCatchFilterThrow | 0.0096ms | | Exceptions, TryCatchFilterThrowApplies | 0.0092ms | | Json, non-ASCII text serialize | 0.6500ms | | Json, non-ASCII text deserialize | 2.1381ms | | Json, small serialize | 0.1419ms | | Json, small deserialize | 0.2167ms | | Json, large serialize | 36.9640ms | | Json, large deserialize | 59.0562ms | | WebSocket, PartialSend 1B | 0.0022ms | | WebSocket, PartialSend 64KB | 0.0690ms | | WebSocket, PartialSend 1MB | 1.1455ms | | WebSocket, PartialReceive 1B | 0.0060ms | | WebSocket, PartialReceive 10KB | 0.0080ms | | WebSocket, PartialReceive 100KB | 0.0000us |
1 parent d6d527f commit 06fb856

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

src/mono/sample/wasm/browser-bench/Exceptions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public ExceptionsTask()
2020
new TryCatchThrow(),
2121
new TryCatchFilter(),
2222
new TryCatchFilterInline(),
23-
//new TryCatchFilterThrow(),
24-
//new TryCatchFilterThrowApplies(),
23+
new TryCatchFilterThrow(),
24+
new TryCatchFilterThrowApplies(),
2525
};
2626
}
2727

@@ -39,7 +39,7 @@ public override void Initialize()
3939

4040
public abstract class ExcMeasurement : BenchTask.Measurement
4141
{
42-
public override int InitialSamples => 10000;
42+
public override int InitialSamples => 100000;
4343
}
4444

4545
class NoExceptionHandling : ExcMeasurement

src/mono/sample/wasm/browser-bench/Json.cs

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using System.Text.Json;
56

67
namespace Sample
@@ -36,6 +37,7 @@ public override Measurement[] Measurements
3637
string smallOrgChartJson;
3738
string largeOrgChartJson;
3839

40+
[UnconditionalSuppressMessage("Trim analysis error", "IL2026")]
3941
public override void Initialize()
4042
{
4143
jsonText = JsonSerializer.Serialize(tc);
@@ -49,6 +51,8 @@ class TextSerialize : BenchTask.Measurement
4951

5052
public TextSerialize(JsonTask task) => this.task = task;
5153
public override string Name => "non-ASCII text serialize";
54+
55+
[UnconditionalSuppressMessage("Trim analysis error", "IL2026")]
5256
public override void RunStep() => JsonSerializer.Serialize(task.tc);
5357
}
5458

@@ -58,6 +62,8 @@ class TextDeserialize : BenchTask.Measurement
5862

5963
public TextDeserialize(JsonTask task) => this.task = task;
6064
public override string Name => "non-ASCII text deserialize";
65+
66+
[UnconditionalSuppressMessage("Trim analysis error", "IL2026")]
6167
public override void RunStep() => JsonSerializer.Deserialize<TextContainer>(task.jsonText);
6268
}
6369

@@ -67,6 +73,8 @@ class SmallSerialize : BenchTask.Measurement
6773

6874
public SmallSerialize(JsonTask task) => this.task = task;
6975
public override string Name => "small serialize";
76+
77+
[UnconditionalSuppressMessage("Trim analysis error", "IL2026")]
7078
public override void RunStep() => JsonSerializer.Serialize(task.smallOrgChart);
7179
}
7280

@@ -76,6 +84,8 @@ class SmallDeserialize : BenchTask.Measurement
7684

7785
public SmallDeserialize(JsonTask task) => this.task = task;
7886
public override string Name => "small deserialize";
87+
88+
[UnconditionalSuppressMessage("Trim analysis error", "IL2026")]
7989
public override void RunStep() => JsonSerializer.Deserialize<Person>(task.smallOrgChartJson);
8090
}
8191

@@ -86,6 +96,8 @@ class LargeSerialize : BenchTask.Measurement
8696
public LargeSerialize(JsonTask task) => this.task = task;
8797
public override string Name => "large serialize";
8898
public override int InitialSamples => 3;
99+
100+
[UnconditionalSuppressMessage("Trim analysis error", "IL2026")]
89101
public override void RunStep() => JsonSerializer.Serialize(task.largeOrgChart);
90102
}
91103

@@ -96,6 +108,8 @@ class LargeDeserialize : BenchTask.Measurement
96108
public LargeDeserialize(JsonTask task) => this.task = task;
97109
public override string Name => "large deserialize";
98110
public override int InitialSamples => 3;
111+
112+
[UnconditionalSuppressMessage("Trim analysis error", "IL2026")]
99113
public override void RunStep() => JsonSerializer.Deserialize<Person>(task.largeOrgChartJson);
100114
}
101115

src/mono/sample/wasm/browser-bench/Program.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Collections.Generic;
67
using System.Text;
78
using System.Text.RegularExpressions;
@@ -19,7 +20,8 @@ public static void Main(string[] args)
1920
BenchTask[] tasks =
2021
{
2122
new ExceptionsTask(),
22-
new JsonTask ()
23+
new JsonTask (),
24+
new WebSocketTask()
2325
};
2426
static Test instance = new Test ();
2527

@@ -30,6 +32,9 @@ public static Task<string> RunBenchmark()
3032
}
3133

3234
[MethodImpl(MethodImplOptions.NoInlining)]
35+
// the constructors of the task we care about are already used when createing tasks field
36+
[UnconditionalSuppressMessage("Trim analysis error", "IL2057")]
37+
[UnconditionalSuppressMessage("Trim analysis error", "IL2072")]
3338
public static void SetTasks(string taskNames)
3439
{
3540
Regex pattern;
@@ -165,7 +170,7 @@ string ResultsSummary ()
165170
time *= 1000;
166171
unit = "us";
167172
}
168-
sb.Append($"| {key,32} | {time,10:F4}{unit} |<br>".Replace (" ", "&nbsp;"));
173+
sb.Append($"| {key.Replace('_',' '),38} | {time,10:F4}{unit} |<br>".Replace (" ", "&nbsp;"));
169174
}
170175
sb.Append("</tt>");
171176

src/mono/sample/wasm/browser-bench/Wasm.Browser.Bench.Sample.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<PropertyGroup>
33
<WasmCopyAppZipToHelixTestDir Condition="'$(ArchiveTests)' == 'true'">true</WasmCopyAppZipToHelixTestDir>
44
<WasmMainJSPath>runtime.js</WasmMainJSPath>
5-
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
65
</PropertyGroup>
76

87
<ItemGroup>

0 commit comments

Comments
 (0)