darklang / dark

Darklang main repo, including language, backend, and infra
https://darklang.com
Other
1.67k stars 91 forks source link

Optimize / trim Blazor #3168

Closed pbiggar closed 2 years ago

pbiggar commented 3 years ago

You should be able to compile the Blazor files using RunAOTCompilation. However, it failed with the following error:

/usr/share/dotnet/sdk/6.0.100-rc.1.21417.9/Sdks/Microsoft.NET.Sdk.BlazorWebAssembly/targets/Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(446,5): error : System.ArgumentException: An item with the same key has already been added. Key: /home/dark/.nuget/packages/fsharp.core/5.0.3-beta.21352.5/contentFiles/any/netstandard2.0/FSharp.Core.xml [/home/dark/app/fsharp-backend/src/Wasm/Wasm.fsproj]
/usr/share/dotnet/sdk/6.0.100-rc.1.21417.9/Sdks/Microsoft.NET.Sdk.BlazorWebAssembly/targets/Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(446,5): error :    at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) [/home/dark/app/fsharp-backend/src/Wasm/Wasm.fsproj]
/usr/share/dotnet/sdk/6.0.100-rc.1.21417.9/Sdks/Microsoft.NET.Sdk.BlazorWebAssembly/targets/Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(446,5): error :    at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) [/home/dark/app/fsharp-backend/src/Wasm/Wasm.fsproj]
/usr/share/dotnet/sdk/6.0.100-rc.1.21417.9/Sdks/Microsoft.NET.Sdk.BlazorWebAssembly/targets/Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(446,5): error :    at Microsoft.NET.Sdk.BlazorWebAssembly.ComputeBlazorPublishAssets.GroupResolvedFilesToPublish(Dictionary`2 resolvedFilesToPublishToRemove, Dictionary`2 resolvedAssemblyToPublish, Dictionary`2 satelliteAssemblyToPublish, Dictionary`2 resolvedSymbolsToPublish, Dictionary`2 resolvedNativeAssetToPublish) [/home/dark/app/fsharp-backend/src/Wasm/Wasm.fsproj]
/usr/share/dotnet/sdk/6.0.100-rc.1.21417.9/Sdks/Microsoft.NET.Sdk.BlazorWebAssembly/targets/Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(446,5): error :    at Microsoft.NET.Sdk.BlazorWebAssembly.ComputeBlazorPublishAssets.Execute() [/home/dark/app/fsharp-backend/src/Wasm/Wasm.fsproj]

Nothing I could do would make this work.

I suspect that once we're not on bleeding edge F# & .NET (we're on a nightly build to make something else work), this might work.

I doubt trimming will work, as we use reflection in the JSON serializers. It doesn't look like source generators are going to be in F# anytime soon, but it might be possible to write the source generator in C#.

pbiggar commented 3 years ago

Steps to test:

pbiggar commented 2 years ago

The latest attempt gets further, but is now blocked by https://github.com/dotnet/aspnetcore/issues/37690

StachuDotNet commented 2 years ago

I spent a few days on this - tried fiddling with .fsproj flags, tried upgrading to .net 6.0.2, 6.0.3, and 7.0.1 - all with no luck. Consistently across those .NET upgrades, the non-publish wwwroot folder works, but the publish folder fails. Likely there's a path forward here, but this was a bit over my head.

I have some unorganized notes here: https://github.com/StachuDotNet/dark-notes/blob/1e07e99d6ae459d6d0fe7a8b5821672891214b82/tasks,%20now/improve%20blazor%20perf%20(aot).md Mostly, some of those links might turn out handy for the next round of attempts - seems we're not the only ones who have struggled in this space.

StachuDotNet commented 2 years ago

We made some discoveries made in a 1:1 with @pbiggar yesterday

Cloning the aspnetcore project (https://github.com/dotnet/aspnetcore/) and compiling the Web.JS project isn't too bad. We can use this to get a reasonable Blazor IO .js module to work with.

There are a few steps involved: