Skip to content

feat: Wasm MemoryDiagnoser#3040

Merged
timcassell merged 2 commits intodotnet:masterfrom
twobrainsgmbh:wasm-memorydiagnoser
Mar 4, 2026
Merged

feat: Wasm MemoryDiagnoser#3040
timcassell merged 2 commits intodotnet:masterfrom
twobrainsgmbh:wasm-memorydiagnoser

Conversation

@FreyLuis
Copy link
Contributor

@FreyLuis FreyLuis commented Mar 2, 2026

This PR enables the MemoryDiagnoser to run on wasm.

Resolves #2226

@FreyLuis
Copy link
Contributor Author

FreyLuis commented Mar 2, 2026

Would the unit test be fine as is? SizeOfAllFields calculates the size platform specific so we can't use it here.

{
{ nameof(AccurateAllocations.EightBytesArray), 8 + objectAllocationOverhead + arraySizeOverhead },
{ nameof(AccurateAllocations.SixtyFourBytesArray), 64 + objectAllocationOverhead + arraySizeOverhead },
{ nameof(AccurateAllocations.AllocateEmptyObject), objectAllocationOverhead },
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing AllocateTask (and the other test is missing the new AllocateEmptyObject).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AllocateTask is the one that depends on SizeOfAllFields to calculate its expected size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I could also just set the expected value to a constant...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the AllocateEmptyObject because it didn't work with the normal and native toolchains. It allocated 24 bytes instead of 16 (objectAllocationOverhead and what CalculateRequiredSpace calculated for an empty class). It was the expected 2 * pointer size with Mono and MonoWasm though...

https://github.com/twobrainsgmbh/BenchmarkDotNet/actions/runs/22619464127/job/65540582849

Since this issue occurred with other toolchains then wasm, it seems out of scope for this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

3 * ptr size is the minimum object size in CLR, I'm surprised mono is able to eliminate the padding.

@FreyLuis FreyLuis force-pushed the wasm-memorydiagnoser branch 2 times, most recently from f9df801 to bfd2252 Compare March 3, 2026 12:20
@FreyLuis FreyLuis force-pushed the wasm-memorydiagnoser branch from bfd2252 to d1e518a Compare March 3, 2026 13:17
@FreyLuis FreyLuis marked this pull request as ready for review March 4, 2026 13:36
@timcassell timcassell merged commit 416275c into dotnet:master Mar 4, 2026
11 checks passed
@timcassell timcassell added this to the v0.16.0 milestone Mar 4, 2026
@FreyLuis FreyLuis deleted the wasm-memorydiagnoser branch March 4, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add MemoryDiagnoser support for WASM

2 participants