Skip to content

Conversation

BrzVlad
Copy link
Member

@BrzVlad BrzVlad commented Sep 22, 2025

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
@Copilot Copilot AI review requested due to automatic review settings September 22, 2025 13:29
Copy link
Contributor

@Copilot Copilot AI left a comment

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
File Description
src/mono/mono/utils/options-def.h Adds new boolean option for compressed interface bitmap feature
src/mono/mono/mini/type-checking.c Replaces compile-time conditional with runtime check for interface bitmap handling
src/mono/mono/mini/mini-runtime.c Updates icall registration to be conditional on runtime option
src/mono/mono/mini/aot-runtime.h Increments AOT file version and adds new flag for compressed interface bitmap
src/mono/mono/mini/aot-runtime.c Adds compatibility check between runtime option and AOT file flags
src/mono/mono/mini/aot-compiler.c Sets AOT flag when compressed interface bitmap is enabled
src/mono/mono/metadata/metadata.c Adds environment variable parsing to control the feature
src/mono/mono/metadata/marshal.c Replaces compile-time conditional with runtime check for stelemref optimization
src/mono/mono/metadata/jit-icall-reg.h Updates icall function name from generic to compressed-specific variant
src/mono/mono/metadata/class-setup-vtable.c Updates bitmap allocation and compression logic to use runtime option
src/mono/mono/metadata/class-internals.h Removes compile-time defines and updates interface matching macros
src/mono/mono/metadata/class-init.c Removes conditional compilation and renames interface match function

Copy link
Member

@vitek-karas vitek-karas left a comment

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.

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

CC @jeffschwMSFT.

@BrzVlad
Copy link
Member Author

BrzVlad commented Sep 22, 2025

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

@BrzVlad
Copy link
Member Author

BrzVlad commented Sep 22, 2025

/ba-g failures are known

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-VM-meta-mono Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants