-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mono][aot] Enable dedup by default for iOS #81319
Conversation
Tagging subscribers to 'os-ios': @steveisok, @akoeplinger Issue DetailsThis PR enables dedup feature in HelloiOS application in non-LLVM debug configuration. It contributes to #80419 by demonstrating the feature on iOS platform. Current implementation uses To enable it in release mode and with LLVM, the following should be resolved:
Detailed analysis of the above-mentioned challenges and list of tasks will be added to the tracking issue. Size reduction in HelloiOS application in non-LLVM debug configuration should be ~ 1.9M with osx-arm64 host and xcode 14.2.
|
Added changes for LLVM and release configurations. |
Preliminary SOD measurements for HelloiOS application using 73da129 snapshot with osx-arm64 host and Xcode 14.2.
Baseline measurements might differ from the dashboard report due to the particular snapshot and Xcode version. The measurements will be repeated for a MAUI application. /cc: @ivanpovazan @LeVladIonescu |
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
/* Use a set of wrappers/instances which work and useful */ | ||
switch (method->wrapper_type) { | ||
case MONO_WRAPPER_RUNTIME_INVOKE: | ||
#ifdef TARGET_WASM | ||
return TRUE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this skipped ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current implementation dedup methods based on a set of predefined rules. During the compilation, shared methods are emitted in corresponding AOT image while inflated instances are emitted in dedup AOT image. During the runtime, the shared method can't be retrieved as it was searched in the dedup AOT image.
Here is an example. During the compilation, the following runtime invoke wrappers are emitted in the dedup AOT image, while generic wrapper (wrapper runtime-invoke) void object:runtime_invoke_dynamic (intptr,intptr,intptr,intptr)
is emitted in a corresponding AOT image.
(wrapper runtime-invoke) object <Module>:runtime_invoke_byte__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_byte (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_int__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_int__this___int_int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_int_int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_uint16__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_uint16 (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_bool__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_byte (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_sbyte__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_sbyte (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_char__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_uint16 (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_int16__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_int16 (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_uint__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_uint (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_long__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_long (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_ulong__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_long (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_intptr__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_intptr (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_uintptr__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_intptr (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_single__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_single (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_double__this___int (object,intptr,intptr,intptr)
(wrapper runtime-invoke) object <Module>:runtime_invoke_void__this___int_double (object,intptr,intptr,intptr)
During the runtime, (wrapper runtime-invoke) void object:runtime_invoke_dynamic (intptr,intptr,intptr,intptr)
was searched in the dedup AOT image as it is RUNTIME_INVOKE_WRAPPER
, but not emitted in the dedup AOT image.
Looks ok, but the restrictions should be investigated. |
Good point. The current restrictions are applied based on iOS-related CI jobs and HelloiOS sample application. The idea was to rollout a single platform at the time, and that is why such strict restrictions are applied. After enabling the dedup by default on iOS, we could first improve size profiling in Mono AOT compiler as outlined in #82101, to get an insight what else could be deduplicated, before enabling the dedup for other platforms and including additional methods. |
/azp run runtime-ioslike |
Azure Pipelines successfully started running 1 pipeline(s). |
@@ -6589,6 +6589,8 @@ emit_and_reloc_code (MonoAotCompile *acfg, MonoMethod *method, guint8 *code, gui | |||
direct_call_target = symbol; | |||
patch_info->type = MONO_PATCH_INFO_NONE; | |||
} else if ((m_class_get_image (patch_info->data.method->klass) == acfg->image) && !got_only && is_direct_callable (acfg, method, patch_info)) { | |||
// FIXME: Currently it only works for wasm. On other platforms it fails as some callees require initialization. | |||
#ifdef TARGET_WASM | |||
MonoCompile *callee_cfg = (MonoCompile *)g_hash_table_lookup (acfg->method_to_cfg, cmethod); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that emit_and_reloc_code () is never used on wasm, so this shouldn't be neccessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, disabled for now. I've added a tracking issue for it as additional size savings might be achieved - #82224
…s require initialization
…e into improvement/dedup-ios
…e into improvement/dedup-ios
/azp run runtime-ioslike |
Azure Pipelines successfully started running 1 pipeline(s). |
Functional and library tests on a device have passed. Failures shouldn't be relevant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This PR enables dedup feature by default for iOS.
Current implementation uses
dedup_methods
hash table for storing extra methods which are emitted in a dedup AOT image. Previously,cfg->skip
flag indedup_skip_methods
is used for indicating if a method should be emitted in an AOT image. As some of the code pointers could point outside the range of methods for an AOT image, only inflated instances are deduplicated.Detailed analysis and limitations are added to the tracking issue.