You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Xamarin.Android.Build.Tasks, monodroid] Optimize member remapping (#7059)
Fixes: #7020
Context: f6f11a5
Commit f6f11a5 introduced type & member remapping. The problem with
its approach was that it used XML as the representation format, which
needed to be parsed during process startup. This would contribute to
app startup slowdowns if there were any remappings, but even if there
weren't any remappings, the minimum App size increased by ~490KB, due
to the added dependencies on `System.Private.Xml.dll` & more.
This app size increase is not ideal.
Remove most of the `.apk` size increases by moving the remapping info
into `libxamarin-app.so`. If no remappings are used, then the size
increase to `libxamarin-app.so` is negligible, and the `.apk` size is
only 61KB larger than pre-f6f11a5a.
~~ API Changes ~~
`Android.Runtime.AndroidTypeManager` gains the following members:
partial class AndroidTypeManager {
struct JniRemappingReplacementMethod {
public string target_type, target_name;
public bool is_static;
}
static extern byte* _monodroid_lookup_replacement_type (
string jniSimpleReference
);
static extern JniRemappingReplacementMethod* _monodroid_lookup_replacement_method_info (
string jniSourceType,
string jniMethodName,
string jniMethodSignature
);
}
`AndroidTypeManager._monodroid_lookup_replacement_type()` replaces
the `JNIEnv.ReplacementTypes` dictionary from f6f11a5.
`AndroidTypeManager._monodroid_lookup_replacement_method_info()`
replaces the `JNIEnv.ReplacementMethods` dictionary from f6f11a5.
Both `_monodroid_lookup_replacement_type()` and
`_monodroid_lookup_replacement_method_info()` are P/Invokes into
`libxamarin-app.so`.
~~ `libxamarin-app.so` Changes ~~
The contents of the `@(_AndroidRemapMembers)` item group are now
stored within `libxamarin-app.so`, with the following structure:
const uint32_t jni_remapping_replacement_method_index_entry_count;
const JniRemappingIndexTypeEntry jni_remapping_method_replacement_index[];
const uint32_t jni_remapping_replacement_type_count;
const JniRemappingTypeReplacementEntry jni_remapping_type_replacements[];
struct JniRemappingString {
const uint32_t length;
const char *str;
};
struct JniRemappingReplacementMethod {
const char *target_type, *target_name;
const bool is_static;
};
struct JniRemappingIndexMethodEntry {
JniRemappingString name, signature;
JniRemappingReplacementMethod replacement
};
struct struct JniRemappingIndexTypeEntry {
JniRemappingString name;
uint32_t method_count;
JniRemappingIndexMethodEntry *methods;
};
struct JniRemappingTypeReplacementEntry {
JniRemappingString name;
const char *replacement;
};
const char *
_monodroid_lookup_replacement_type (const char *);
const JniRemappingReplacementMethod*
_monodroid_lookup_replacement_method_info (const char *jniSourceType, const char *jniMethodName, const char *jniMethodSignature);
Referring to the `<replacements/>` XML from f6f11a5 in
`@(_AndroidRemapMembers)`:
* `//replace-type/@from` fills `JniRemappingTypeReplacementEntry::name`,
`//replace-type/@to` fills `JniRemappingTypeReplacementEntry::replacement`,
and `_monodroid_lookup_replacement_type()` performs a linear
search over `jni_remapping_type_replacements`.
* `//replace-method/@source-type` fills `JniRemappingIndexTypeEntry::name`,
`//replace-method/@source-method-name` fills `JniRemappingIndexMethodEntry::name`,
`//replace-method/@source-method-signature` fills `JniRemappingIndexMethodEntry::signature`,
`//replace-method/@target-type` fills `JniRemappingReplacementMethod::target_type`,
`//replace-method/@target-method-name` fills `JniRemappingReplacementMethod::target_name`,
`//replace-method/@target-method-signature` and
`//replace-method/@target-method-parameter-count` are *ignored*,
`//replace-method/@target-method-instance-to-static` fills `JniRemappingReplacementMethod::is_static`,
and `_monodroid_lookup_replacement_method_info()` performs a
search over `jni_remapping_method_replacement_index` looking for
entries with "matching" type names, method names, and method
signatures, and once a match is found it returns a pointer to the
`JniRemappingReplacementMethod` instance.
Co-authored-by: Jonathan Peppers <[email protected]>
Log.LogError($"Attribute 'target-method-instance-to-static' in element '{reader.LocalName}' value '{targetIsStatic}' cannot be parsed as boolean; {RemappingXmlFilePath.ItemSpec} line {GetCurrentLineNumber()}");
0 commit comments