Skip to content

Get the full WebAssembly pipeline working for much smaller web build#417

Merged
initsu merged 4 commits into
Ellendar:mainfrom
TheRealQuantam:BrowserDiet
May 22, 2026
Merged

Get the full WebAssembly pipeline working for much smaller web build#417
initsu merged 4 commits into
Ellendar:mainfrom
TheRealQuantam:BrowserDiet

Conversation

@TheRealQuantam
Copy link
Copy Markdown
Collaborator

Previously the web version was using a frankenbuild that wasn't doing important WASM steps like compressing files. This PR gets it properly set up for a WASM build. This reduces the files published from 61.7 MB to 14.2 MB.

Currently trimming is disabled. It may be possible to shrink it another few megs by getting trimming working, but it will take additional work.

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk.WebAssembly">
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem exists between line 1 and line 2

// identify runtime/assembly payloads
const isBootResource = (url, res) => {
const u = (typeof url === "string" ? url : url.url || "").toLowerCase();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too sure, but after getting publish working regular Visual Studio launched builds wouldn't work. Gemini suggested this and it fixed it.

@initsu
Copy link
Copy Markdown
Collaborator

initsu commented May 22, 2026

It doesn't load in browser when I build it as release. I get this error:

System.DllNotFoundException: libSkiaSharp

I built it using
dotnet publish -c Release CrossPlatformUI.Browser/CrossPlatformUI.Browser.csproj

and then ran it with
dotnet serve
from CrossPlatformUI.Browser\bin\Release\net10.0-browser\publish\wwwroot

I wanted to test the performance. The performance was really bad before we added AoT and you disabled AoT so I have doubts (but things may have improved in .NET 10).

@initsu
Copy link
Copy Markdown
Collaborator

initsu commented May 22, 2026

Also, the web app is currently hosted as a GitHub Pages site, and they do not serve precompressed .gz or .br files even if they exist. It will just do on-the-fly Gzip compression. So generating those files won't help unless we change to something else (which I don't think is worth it.) It's good to have the option to generate them in the future tho.

@TheRealQuantam
Copy link
Copy Markdown
Collaborator Author

TheRealQuantam commented May 22, 2026

Here's exactly what I did to build and serve it:

H:\Emulation\Z2Randomizer-dev\CrossPlatformUI.Browser>dotnet publish -c Release
H:\Emulation\Z2Randomizer-dev\CrossPlatformUI.Browser>dotnet serve -o -c -d bin\Release\net10.0-browser\publish

I can also, in Visual Studio, open it with CrossPlatformUI.Browser -> Debug -> Start New Instance / Start Without Debugging. Both methods allow me to load it and generate a ROM.

Not clear what's different for you.

@TheRealQuantam
Copy link
Copy Markdown
Collaborator Author

Also, the web app is currently hosted as a GitHub Pages site, and they do not serve precompressed .gz or .br files even if they exist. It will just do on-the-fly Gzip compression. So generating those files won't help unless we change to something else (which I don't think is worth it.) It's good to have the option to generate them in the future tho.

Hum. That sucks.

@initsu
Copy link
Copy Markdown
Collaborator

initsu commented May 22, 2026

Thanks for clarifying. I got it working too. I had to reinstall wasm-tools (at least I think that was it).

Hm... it's definitely slower than the current live version that has AoT for me. If you find a flag & seed combination that takes a little while to generate, you can compare with the same seed on https://z2r.app/

@TheRealQuantam
Copy link
Copy Markdown
Collaborator Author

So getting trimming working turned out to be easier than I expected. Actually I took one look at the 806 trim warnings it generated and assumed it was not going to work, without seeing that the AppBundle version itself had as many trim warnings, and both work just fine. Thus I can add trimming and AOT to this PR.

Now, there were two things I didn't realize before this PR:

  1. GitHub Pages won't serve the compressed versions of the files
  2. GitHub Pages does on the fly gzip compression

That changes the value equation. The uncompressed AppBundle directory before this PR is 105 MB (estimated to be ~30 MB compressed on the fly). This PR, with trimming and AOT, is 85 MB uncompressed, or 20% smaller.

According to Gemini it's possible to manually download and decompress the compressed files in main.js, but that's beyond my capabilities. If somebody can get that working that would bring it down to like 17 MB, or 45% smaller than pre-PR compressed form.

@initsu
Copy link
Copy Markdown
Collaborator

initsu commented May 22, 2026

Running dotnet serve with --gzip and --brotli respectively, and fully reloading the page gave me these numbers:

28.6 MB downloaded with gzip
26.8 MB downloaded brotli

It would be a small further improvement but does not seem worth it.

Anyway, this looks good to me now. I will squash and merge this to main

@initsu initsu merged commit 14887c0 into Ellendar:main May 22, 2026
1 check passed
@TheRealQuantam TheRealQuantam deleted the BrowserDiet branch May 22, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants