Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
<EnableAggressiveTrimming Condition="'$(EnableAOTAndTrimming)' != ''">$(EnableAOTAndTrimming)</EnableAggressiveTrimming>
<PublishTrimmed Condition="'$(EnableAOTAndTrimming)' != ''">$(EnableAOTAndTrimming)</PublishTrimmed>
<RunAOTCompilation Condition="'$(EnableAOTAndTrimming)' != ''">$(EnableAOTAndTrimming)</RunAOTCompilation>
<!-- the default heap size is ~512MB, which is too much because AppStart loads more copies
of the wasm runtime and can leak a few of them. the result is that browser-bench's memory
usage can climb as high as 3GB or more and then fail -->
<EmccInitialHeapSize>83886080</EmccInitialHeapSize>
</PropertyGroup>

<ItemGroup>
Expand Down
7 changes: 6 additions & 1 deletion src/mono/wasm/build/WasmApp.Native.targets
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@
<Error Condition="'$(_IsEMSDKMissing)' == 'true'"
Text="$(_EMSDKMissingErrorMessage) Emscripten SDK is required for building native files." />

<AssembliesTotalSize Assemblies="@(WasmAssembliesToBundle)">
<Output TaskParameter="TotalSize" PropertyName="_WasmAssembliesTotalSize" />
</AssembliesTotalSize>

<PropertyGroup>
<_MonoAotCrossCompilerPath>@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','browser-wasm'))</_MonoAotCrossCompilerPath>
<_EmccDefaultFlagsRsp>$([MSBuild]::NormalizePath($(_WasmRuntimePackSrcDir), 'emcc-default.rsp'))</_EmccDefaultFlagsRsp>
Expand Down Expand Up @@ -188,7 +192,8 @@
<_EmccLinkRsp>$(_WasmIntermediateOutputPath)emcc-link.rsp</_EmccLinkRsp>

<EmccInitialHeapSize Condition="'$(EmccInitialHeapSize)' == ''">$(EmccTotalMemory)</EmccInitialHeapSize>
<EmccInitialHeapSize Condition="'$(EmccInitialHeapSize)' == ''">536870912</EmccInitialHeapSize>
<EmccInitialHeapSize Condition="'$(EmccInitialHeapSize)' == '' and '$(_WasmAssembliesTotalSize)' != '' and $(_WasmAssembliesTotalSize) > 16777216">$(_WasmAssembliesTotalSize)</EmccInitialHeapSize>
<EmccInitialHeapSize Condition="'$(EmccInitialHeapSize)' == ''">16777216</EmccInitialHeapSize>
</PropertyGroup>

<ItemGroup>
Expand Down
7 changes: 6 additions & 1 deletion src/mono/wasm/build/WasmApp.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<UsingTask TaskName="WasmAppBuilder" AssemblyFile="$(WasmAppBuilderTasksAssemblyPath)" />
<UsingTask TaskName="WasmLoadAssembliesAndReferences" AssemblyFile="$(WasmAppBuilderTasksAssemblyPath)" />
<UsingTask TaskName="AssembliesTotalSize" AssemblyFile="$(WasmAppBuilderTasksAssemblyPath)" />

<!--
Required public items/properties:
Expand Down Expand Up @@ -51,7 +52,7 @@
- $(EmccFlags) - Emcc flags used for both compiling native files, and linking
- $(EmccExtraLDFlags) - Extra emcc flags for linking
- $(EmccExtraCFlags) - Extra emcc flags for compiling native files
- $(EmccInitialHeapSize) - Initial heap size specified with `emcc`. Default value: 536870912
- $(EmccInitialHeapSize) - Initial heap size specified with `emcc`. Default value: 16777216 or size of the DLLs.
Corresponds to `INITIAL_MEMORY` arg for emcc.
(previously named EmccTotalMemory, which is still kept as an alias)

Expand Down Expand Up @@ -203,6 +204,10 @@
<WasmAssembliesToBundle Include="$(PublishDir)\**\*.dll" />
</ItemGroup>

<AssembliesTotalSize Assemblies="@(WasmAssembliesToBundle)">
<Output TaskParameter="TotalSize" PropertyName="_WasmAssembliesTotalSize" />
</AssembliesTotalSize>

<PropertyGroup Condition="'$(_WasmRuntimeConfigFilePath)' == ''">
<_WasmRuntimeConfigFilePath Condition="$([System.String]::new(%(PublishItemsOutputGroupOutputs.Identity)).EndsWith('$(AssemblyName).runtimeconfig.json'))">@(PublishItemsOutputGroupOutputs)</_WasmRuntimeConfigFilePath>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/wasm.proj
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<PropertyGroup>
<_EmccExportedRuntimeMethods>&quot;[@(EmccExportedRuntimeMethod -> '%27%(Identity)%27', ',')]&quot;</_EmccExportedRuntimeMethods>
<_EmccExportedFunctions>@(EmccExportedFunction -> '%(Identity)',',')</_EmccExportedFunctions>
<EmccInitialHeapSize>536870912</EmccInitialHeapSize>
<EmccInitialHeapSize>16777216</EmccInitialHeapSize>
</PropertyGroup>
<ItemGroup>
<_EmccLinkFlags Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" />
Expand Down
44 changes: 44 additions & 0 deletions src/tasks/WasmAppBuilder/AssembliesTotalSize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

// estimate the total size of the assemblies we are going to load x2 and round it up to 64K
public class AssembliesTotalSize : Task
{
[Required]
[NotNull]
public string[]? Assemblies { get; set; }

[Output]
public long? TotalSize { get; private set; }

public override bool Execute ()
{
long totalSize=0;
foreach (var asm in Assemblies)
{
var info = new FileInfo(asm);
if (!info.Exists)
{
Log.LogError($"Could not find assembly '{asm}'");
return false;
}
totalSize += info.Length;
}
totalSize *= 2;
totalSize += 0x10000;
totalSize &= 0xFFFF0000;

TotalSize = totalSize;

return true;
}
}