Skip to content

[release/10.0] [mono] Make the compressed interface bitmap feature usable - #119953

Merged
agocke merged 2 commits into
dotnet:release/10.0from
BrzVlad:backport-compressed-interface-bitmap
Sep 22, 2025
Merged

[release/10.0] [mono] Make the compressed interface bitmap feature usable#119953
agocke merged 2 commits into
dotnet:release/10.0from
BrzVlad:backport-compressed-interface-bitmap

Conversation

@BrzVlad

Copy link
Copy Markdown
Member

When this option is enabled, the env var MONO_COMPRESSED_INTERFACE_BITMAP=1 is passed, the bitmap that stores the set of implemented interfaces by a class is saved in a compressed format. This has significant memory improvement on applications using a lot of types.

Customer Impact

  • Customer reported
  • Found internally

This issue was discovered on a large customer application. The memory usage of these bitmaps was so big in this scenario that the application got killed by iOS.

Regression

  • Yes
  • No

The memory increase above the tipping point was caused by more types used after transitioning from xamarin to maui. However, this is not strictly a regression.

Testing

This was tested on the customer application. Also this new option was tested with our own set of tests.

Risk

Low. This feature is disabled by default so there shouldn't be any impact on existing applications. This PR adds the possibility to use this optimization, which was slightly bit-rotten and behind a compile time define before.

…t#119694)
* [mono][metadata] Enable compressed interface bitmap by default
* Fix build on windows
* Fix publishing of compressed bitmap
Before this commit we were doing changes on the published data which is problematic for multithreaded environments. We ensure the bitmap is fully processed before publishing it so that we can rely on the data dependency memory ordering constraint for correctness.
…tmap feature (dotnet#119881)
* Add option to configure use of compressed interface bitmaps
This optimization is disabled by default. Enable it with `MONO_COMPRESSED_INTERFACE_BITMAP=1`
* Add support for detecting mismatch with aot images

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables the compressed interface bitmap feature in Mono runtime by making it controllable via the environment variable MONO_COMPRESSED_INTERFACE_BITMAP instead of requiring a compile-time definition. This optimization compresses the bitmap used to store implemented interfaces for classes, providing significant memory savings for applications with many types.

Key changes:

  • Replaces compile-time COMPRESSED_INTERFACE_BITMAP define with runtime mono_opt_compressed_interface_bitmap option
  • Adds environment variable MONO_COMPRESSED_INTERFACE_BITMAP support for enabling/disabling the feature
  • Updates AOT file format to track compressed interface bitmap usage

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
src/mono/mono/utils/options-def.hAdds new boolean option for compressed interface bitmap feature
src/mono/mono/mini/type-checking.cReplaces compile-time conditional with runtime check for interface bitmap handling
src/mono/mono/mini/mini-runtime.cUpdates icall registration to be conditional on runtime option
src/mono/mono/mini/aot-runtime.hIncrements AOT file version and adds new flag for compressed interface bitmap
src/mono/mono/mini/aot-runtime.cAdds compatibility check between runtime option and AOT file flags
src/mono/mono/mini/aot-compiler.cSets AOT flag when compressed interface bitmap is enabled
src/mono/mono/metadata/metadata.cAdds environment variable parsing to control the feature
src/mono/mono/metadata/marshal.cReplaces compile-time conditional with runtime check for stelemref optimization
src/mono/mono/metadata/jit-icall-reg.hUpdates icall function name from generic to compressed-specific variant
src/mono/mono/metadata/class-setup-vtable.cUpdates bitmap allocation and compression logic to use runtime option
src/mono/mono/metadata/class-internals.hRemoves compile-time defines and updates interface matching macros
src/mono/mono/metadata/class-init.cRemoves conditional compilation and renames interface match function

Comment threadsrc/mono/mono/metadata/class-init.c
Comment threadsrc/mono/mono/metadata/class-init.c

@vitek-karasvitek-karas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Aside from the two nits from Copilot, this looks good.

@JulieLeeMSFTJulieLeeMSFT added the Servicing-approved Approved for servicing release label Sep 22, 2025
@JulieLeeMSFTJulieLeeMSFT added this to the 10.0.0 milestone Sep 22, 2025
@JulieLeeMSFT

Copy link
Copy Markdown
Member

CC @jeffschwMSFT.

@BrzVlad

Copy link
Copy Markdown
MemberAuthor

All failures are tracked. Build analysis seems to have the wrong status. @jeffschwMSFT

@BrzVlad

Copy link
Copy Markdown
MemberAuthor

/ba-g failures are known

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-VM-meta-monoServicing-approvedApproved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@BrzVlad@JulieLeeMSFT@vitek-karas@agocke