Skip to content

Conversation

BrzVlad
Copy link
Member

@BrzVlad BrzVlad commented Sep 26, 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. It was also tested with our own set of tests, it was enabled for a few weeks on main.

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
@BrzVlad BrzVlad requested a review from lambdageek as a code owner September 26, 2025 18:16
@Copilot Copilot AI review requested due to automatic review settings September 26, 2025 18:16
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 by replacing compile-time #ifdef guards with runtime checks based on the mono_opt_compressed_interface_bitmap option. The feature compresses the bitmap that stores implemented interfaces by classes, providing significant memory improvements for applications with many types.

Key changes:

  • Replaced compile-time feature guards with runtime option checks
  • Added environment variable support for enabling the feature via MONO_COMPRESSED_INTERFACE_BITMAP=1
  • Updated AOT compilation to handle the compressed bitmap flag compatibility

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 Added runtime option definition for compressed interface bitmap
src/mono/mono/mini/type-checking.c Replaced compile-time guards with runtime checks for interface bitmap emission
src/mono/mono/mini/mini-runtime.c Made icall registration conditional on runtime option
src/mono/mono/mini/aot-runtime.h Added new AOT file flag and incremented version
src/mono/mono/mini/aot-runtime.c Added compatibility check for compressed bitmap feature
src/mono/mono/mini/aot-compiler.c Set AOT flag when compressed bitmap option is enabled
src/mono/mono/metadata/metadata.c Added environment variable parsing for feature enablement
src/mono/mono/metadata/marshal.c Replaced compile-time conditional with runtime check
src/mono/mono/metadata/jit-icall-reg.h Renamed icall function from generic to compressed-specific
src/mono/mono/metadata/class-setup-vtable.c Updated bitmap allocation logic for runtime option
src/mono/mono/metadata/class-internals.h Updated macros and function declarations for runtime support
src/mono/mono/metadata/class-init.c Added explicit casts and renamed function for compressed bitmap handling

@BrzVlad BrzVlad added Servicing-consider Issue for next servicing release review Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Sep 26, 2025
@BrzVlad
Copy link
Member Author

BrzVlad commented Oct 1, 2025

/ba-g wasm failure unrelated

@steveisok steveisok merged commit 4def3e8 into dotnet:release/9.0-staging Oct 1, 2025
92 of 98 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants