Skip to content

Conversation

BrzVlad
Copy link
Member

@BrzVlad BrzVlad commented Sep 19, 2025

After enabling this by default in #119694, a few microbenchmark regression can be seen with checking if an object implements an interface. In order to make an easier transition into this feature, add a new env var MONO_COMPRESSED_INTERFACE_BITMAP which can be checked at runtime to enable this feature. AOT compiled code must have identical feature enabling so that the images are compatible at runtime.

This optimization is disabled by default. Enable it with `MONO_COMPRESSED_INTERFACE_BITMAP=1`
@Copilot Copilot AI review requested due to automatic review settings September 19, 2025 07:06
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 runtime configuration of the compressed interface bitmap feature in Mono through a new environment variable MONO_COMPRESSED_INTERFACE_BITMAP. The feature was previously enabled by default but caused performance regressions in interface checking microbenchmarks, so this change allows users to toggle it at runtime for easier transition.

Key changes:

  • Add runtime option compressed-interface-bitmap that can be controlled via environment variable
  • Replace compile-time #ifdef COMPRESSED_INTERFACE_BITMAP conditionals with runtime checks using mono_opt_compressed_interface_bitmap
  • Update AOT file format version and add compatibility checks to ensure AOT images match runtime configuration

Reviewed Changes

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

Show a summary per file
File Description
src/mono/mono/utils/options-def.h Adds new boolean option for compressed interface bitmap
src/mono/mono/metadata/metadata.c Implements environment variable parsing to set the runtime option
src/mono/mono/mini/type-checking.c Converts compile-time conditional to runtime check for interface bitmap generation
src/mono/mono/mini/mini-runtime.c Makes icall registration conditional on runtime option
src/mono/mono/mini/aot-runtime.h Updates AOT file version and adds new flag for compressed interface bitmap
src/mono/mono/mini/aot-runtime.c Adds compatibility check between AOT image and runtime configuration
src/mono/mono/mini/aot-compiler.c Sets AOT flag based on runtime option during compilation
src/mono/mono/metadata/marshal.c Converts compile-time conditional to runtime check for stelemref optimization
src/mono/mono/metadata/jit-icall-reg.h Updates icall name from mono_class_interface_match to mono_class_interface_match_compressed
src/mono/mono/metadata/class-setup-vtable.c Converts compile-time conditionals to runtime checks for bitmap allocation and compression
src/mono/mono/metadata/class-internals.h Updates interface matching macros to use runtime checks and renames compressed matching function
src/mono/mono/metadata/class-init.c Renames compressed interface matching function and removes compile-time conditional

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.

LGTM - thanks!

@BrzVlad
Copy link
Member Author

BrzVlad commented Sep 22, 2025

/ba-g llvm and ios-like failures are all unrelated

@BrzVlad BrzVlad merged commit 04a748b into dotnet:main Sep 22, 2025
80 of 86 checks passed
@BrzVlad
Copy link
Member Author

BrzVlad commented Sep 22, 2025

/backport to release/10.0

Copy link
Contributor

Copy link
Contributor

@BrzVlad backporting to "release/10.0" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Add option to configure use of compressed interface bitmaps
Using index info to reconstruct a base tree...
M	src/mono/mono/metadata/class-init.c
M	src/mono/mono/metadata/class-internals.h
M	src/mono/mono/metadata/class-setup-vtable.c
M	src/mono/mono/metadata/marshal.c
M	src/mono/mono/metadata/metadata.c
M	src/mono/mono/mini/type-checking.c
Falling back to patching base and 3-way merge...
Auto-merging src/mono/mono/metadata/class-init.c
Auto-merging src/mono/mono/metadata/class-internals.h
CONFLICT (content): Merge conflict in src/mono/mono/metadata/class-internals.h
Auto-merging src/mono/mono/metadata/class-setup-vtable.c
CONFLICT (content): Merge conflict in src/mono/mono/metadata/class-setup-vtable.c
Auto-merging src/mono/mono/metadata/marshal.c
Auto-merging src/mono/mono/metadata/metadata.c
Auto-merging src/mono/mono/mini/type-checking.c
CONFLICT (content): Merge conflict in src/mono/mono/mini/type-checking.c
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Add option to configure use of compressed interface bitmaps
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

BrzVlad added a commit to BrzVlad/runtime that referenced this pull request Sep 22, 2025
…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
agocke pushed a commit that referenced this pull request Sep 22, 2025
…able (#119953)

* [mono][metadata] Enable compressed interface bitmap by default (#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.

* [mono] Enable configuration at runtime of the compressed interface bitmap feature (#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 added a commit to BrzVlad/runtime that referenced this pull request Sep 26, 2025
…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
steveisok pushed a commit that referenced this pull request Oct 1, 2025
…ble (#120154)

* [mono][metadata] Enable compressed interface bitmap by default (#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.

* [mono] Enable configuration at runtime of the compressed interface bitmap feature (#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
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.

2 participants