-
Notifications
You must be signed in to change notification settings - Fork 5k
[browser] improve default initial memory size #80507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pavelsavara
merged 20 commits into
dotnet:main
from
pavelsavara:browser_initial_heap_size
Jan 24, 2023
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a5fb483
make initial size small again
pavelsavara 87c28ce
bench
pavelsavara 0851542
Merge branch 'main' into browser_initial_heap_size
pavelsavara 52c0f1d
Merge branch 'main' into browser_initial_heap_size
pavelsavara bf478e4
Merge branch 'main' into browser_initial_heap_size
pavelsavara 4da3be8
make EmccInitialHeapSize dynamic based on size of the assemblies
pavelsavara 1e5cdcd
2x
pavelsavara df98dcc
naming feedback
pavelsavara b536b38
feedback
pavelsavara 0eb9f8e
feedback
pavelsavara d362ab8
add AOT data segment size using llvm-size tool
pavelsavara 292feef
whitespace
pavelsavara 6a169ac
Merge branch 'main' into browser_initial_heap_size
pavelsavara c688a1a
feedback
pavelsavara f92e9ff
Update src/mono/wasm/build/WasmApp.targets
pavelsavara f47fac1
Update src/tasks/WasmAppBuilder/WasmCalculateInitialHeapSize.cs
pavelsavara 28fd57c
Update src/tasks/WasmAppBuilder/WasmCalculateInitialHeapSize.cs
pavelsavara 358f8d5
Update src/tasks/WasmAppBuilder/WasmCalculateInitialHeapSize.cs
pavelsavara c7caa73
feedback
pavelsavara 2c2a88e
Merge branch 'main' into browser_initial_heap_size
pavelsavara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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.IO; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
|
||
pavelsavara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
namespace Microsoft.WebAssembly.Build.Tasks; | ||
|
||
/// <summary>estimate the total memory needed for the assemblies and AOT data segments.</summary> | ||
public class WasmCalculateInitialHeapSize : Task | ||
pavelsavara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
[Required] | ||
public string[] Assemblies { get; set; } = Array.Empty<string>(); | ||
|
||
public string[] AOTDataSegmentSizes { get; set; } = Array.Empty<string>(); | ||
|
||
[Output] | ||
public long InitialHeapSize { get; private set; } | ||
|
||
public override bool Execute() | ||
{ | ||
long totalDllSize = 0; | ||
long totalDataSize = 0; | ||
|
||
foreach (string asm in Assemblies) | ||
{ | ||
var info = new FileInfo(asm); | ||
if (!info.Exists) | ||
{ | ||
Log.LogError($"Could not find assembly '{asm}'"); | ||
return false; | ||
} | ||
totalDllSize += info.Length; | ||
} | ||
|
||
// during non-AOT builds, AOTDataSegmentSizes is empty | ||
foreach (string segment in AOTDataSegmentSizes) | ||
{ | ||
if (!long.TryParse(segment, out long segmentSize)) | ||
{ | ||
Log.LogError($"Could not parse AOT Data segment size '{segment}"); | ||
return false; | ||
} | ||
totalDataSize += segmentSize; | ||
} | ||
|
||
// this is arbitrary guess about memory overhead of the runtime, after the assemblies are loaded | ||
const double extraMemoryRatio = 1.2; | ||
// plus size of data segments generated by AOT | ||
long memorySize = totalDataSize + (long)(totalDllSize * extraMemoryRatio); | ||
|
||
// round it up to 64KB page size for wasm | ||
InitialHeapSize = (memorySize + 0x10000) & 0xFFFF0000; | ||
|
||
return true; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.