Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
naming feedback
  • Loading branch information
pavelsavara committed Jan 17, 2023
commit df98dccc3312925f165130a14582ff772be6196b
8 changes: 4 additions & 4 deletions src/mono/wasm/build/WasmApp.Native.targets
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@
<Error Condition="'$(_IsEMSDKMissing)' == 'true'"
Text="$(_EMSDKMissingErrorMessage) Emscripten SDK is required for building native files." />

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

<PropertyGroup>
<_MonoAotCrossCompilerPath>@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','browser-wasm'))</_MonoAotCrossCompilerPath>
Expand Down Expand Up @@ -192,7 +192,7 @@
<_EmccLinkRsp>$(_WasmIntermediateOutputPath)emcc-link.rsp</_EmccLinkRsp>

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

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

<!--
Required public items/properties:
Expand Down Expand Up @@ -204,9 +204,9 @@
<WasmAssembliesToBundle Include="$(PublishDir)\**\*.dll" />
</ItemGroup>

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

<PropertyGroup Condition="'$(_WasmRuntimeConfigFilePath)' == ''">
<_WasmRuntimeConfigFilePath Condition="$([System.String]::new(%(PublishItemsOutputGroupOutputs.Identity)).EndsWith('$(AssemblyName).runtimeconfig.json'))">@(PublishItemsOutputGroupOutputs)</_WasmRuntimeConfigFilePath>
Expand Down
18 changes: 10 additions & 8 deletions src/tasks/WasmAppBuilder/AssembliesTotalSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
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
// estimate the total memory needed for the assemblies
public class WasmCalculateInitialHeapSize : Task
{
[Required]
[NotNull]
Expand All @@ -22,7 +22,7 @@ public class AssembliesTotalSize : Task

public override bool Execute ()
{
long totalSize=0;
long totalDllSize=0;
foreach (var asm in Assemblies)
{
var info = new FileInfo(asm);
Expand All @@ -31,13 +31,15 @@ public override bool Execute ()
Log.LogError($"Could not find assembly '{asm}'");
return false;
}
totalSize += info.Length;
totalDllSize += info.Length;
}
totalSize *= 2;
totalSize += 0x10000;
totalSize &= 0xFFFF0000;

TotalSize = totalSize;
// this is arbitrary guess about memory overhead of the runtime, after the assemblies are loaded
const double extraMemoryRatio = 1.2;
long memorySize = (long) (totalDllSize * extraMemoryRatio);

// round it up to 64KB page size for wasm
TotalSize = (memorySize + 0x10000) & 0xFFFF0000;

return true;
}
Expand Down