Skip to content

Commit

Permalink
[browser] benchmark - generated JSON serializer (#81475)
Browse files Browse the repository at this point in the history
* generated JSON serializer
* With that we can trim again
* fix console bench
Co-authored-by: Radek Doulik <radek.doulik@gmail.com>
  • Loading branch information
pavelsavara committed Feb 1, 2023
1 parent 047ea6a commit 47dd02a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@
<Compile Remove="../Browser.cs" />
<PackageReference Include="Mono.Options" Version="6.12.0.148" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\..\libraries\System.Text.Json\gen\System.Text.Json.SourceGeneration.Roslyn4.0.csproj"
ReferenceOutputAssembly="false"
OutputItemType="Analyzer" />
</ItemGroup>
</Project>
32 changes: 11 additions & 21 deletions src/mono/sample/wasm/browser-bench/Json.cs

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/mono/sample/wasm/browser-bench/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;

namespace Sample
{
Expand Down Expand Up @@ -35,4 +36,16 @@ public static Person GenerateOrgChart(int totalDepth, int numDescendantsPerNode,
};
}
}

class TextContainer
{
public string Text { get; set; }
}

[JsonSerializable(typeof(TextContainer))]
[JsonSerializable(typeof(Person))]
[JsonSerializable(typeof(List<Person>))]
[JsonSerializable(typeof(Dictionary<string, object>))]
partial class TestSerializerContext : JsonSerializerContext { }

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<EnableAggressiveTrimming Condition="'$(EnableAOTAndTrimming)' != ''">$(EnableAOTAndTrimming)</EnableAggressiveTrimming>
<PublishTrimmed Condition="'$(EnableAOTAndTrimming)' != ''">$(EnableAOTAndTrimming)</PublishTrimmed>
<RunAOTCompilation Condition="'$(EnableAOTAndTrimming)' != ''">$(EnableAOTAndTrimming)</RunAOTCompilation>
<TrimMode>partial</TrimMode>
</PropertyGroup>

<ItemGroup>
Expand All @@ -22,4 +21,9 @@

<Target Name="RunSample" DependsOnTargets="RunSampleWithBrowserAndSimpleServer" />

<ItemGroup>
<ProjectReference Include="..\..\..\..\libraries\System.Text.Json\gen\System.Text.Json.SourceGeneration.Roslyn4.0.csproj"
ReferenceOutputAssembly="false"
OutputItemType="Analyzer" />
</ItemGroup>
</Project>
54 changes: 26 additions & 28 deletions src/mono/sample/wasm/browser-bench/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,37 +98,35 @@ class MainApp {
setTasks(tasks.join(','));
}

this.yieldBench();
}
const r = await fetch("/bootstrap.flag", {
method: 'POST',
body: "ok"
});
console.log("bootstrap post request complete, response: ", r);

bootstraped = false;
while (true) {
const resultString = await this.yieldBench();
if (resultString.length == 0) break;
document.getElementById("out").innerHTML += resultString;
console.log(resultString);
}

yieldBench() {
let promise = runBenchmark();
promise.then(ret => {
if (!this.bootstraped) {
fetch("/bootstrap.flag", {
method: 'POST',
body: "ok"
}).then(r => { console.log("bootstrap post request complete, response: ", r); });
this.bootstraped = true;
}
document.getElementById("out").innerHTML += ret;
if (ret.length > 0) {
setTimeout(() => { this.yieldBench(); }, 0);
} else {
_jiterpreter_dump_stats();
document.getElementById("out").innerHTML += "Finished";
fetch("/results.json", {
method: 'POST',
body: getFullJsonResults()
}).then(r => { console.log("post request complete, response: ", r); });
fetch("/results.html", {
method: 'POST',
body: document.getElementById("out").innerHTML
}).then(r => { console.log("post request complete, response: ", r); });
}
_jiterpreter_dump_stats();
document.getElementById("out").innerHTML += "Finished";
const r1 = await fetch("/results.json", {
method: 'POST',
body: getFullJsonResults()
});
console.log("post request complete, response: ", r1);
const r2 = await fetch("/results.html", {
method: 'POST',
body: document.getElementById("out").innerHTML
});
console.log("post request complete, response: ", r2);
}

yieldBench() {
return new Promise(resolve => setTimeout(() => resolve(runBenchmark()), 0));
}

async pageShow() {
Expand Down

0 comments on commit 47dd02a

Please sign in to comment.