镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

The Java.Interop.TypeManager static constructor allocates lots of strings #1829

Closed

Description

@jonpryor

When recently profiling Xamarin.Android application startup, we observed that lots of strings were being allocated by the Java.Interop.TypeManager static constructor.

These are probably coming from the __TypeRegistrations.RegisterPackages() call: https://github.com/xamarin/xamarin-android/blob/bb8183c8c16667b18ba9197e78294b17a0af532c/src/Mono.Android/Java.Interop/TypeManager.cs#L34

That's from a generated file; src/Mono.Android/obj/Debug/android-27//mcw/Java.Interop.__TypeRegistrations.cs partially contains:

	partial class __TypeRegistrations {

		public static void RegisterPackages ()
		{
#if MONODROID_TIMING
			var start = DateTime.Now;
			Android.Util.Log.Info ("MonoDroid-Timing", "RegisterPackages start: " + (start - new DateTime (1970, 1, 1)).TotalMilliseconds);
#endif // def MONODROID_TIMING
			Java.Interop.TypeManager.RegisterPackages (
					new string[]{
						"android",
						"android/accessibilityservice",
						"android/gesture",
						// ...
					},
					new Converter<string, Type>[]{
						lookup_android_package,
						// ...
					});
#if MONODROID_TIMING
			var end = DateTime.Now;
			Android.Util.Log.Info ("MonoDroid-Timing", "RegisterPackages time: " + (end - new DateTime (1970, 1, 1)).TotalMilliseconds + " [elapsed: " + (end - start).TotalMilliseconds + " ms]");
#endif // def MONODROID_TIMING
		}

Can all of the strings in here be avoided (type maps?) or deferred until laster so it's not part of process startup?

VS bug #635224

Activity

  1. added this to the d15-9 milestone on Jun 15, 2018
  2. added
    vs-syncFor internal use only; creates a VSTS "mirror" issue.
    on Jun 18, 2018
  3. jonpryor commented on Jul 2, 2018

    @jonpryor
    ContributorAuthor

    On further thought, the typemap.mj and typemap.jm files suggest that __TypeRegistrations.RegisterPackages() shouldn't be needed at all. Removing them entirely -- or at least not calling them -- should help with the strings allocated and overall startup time.

  4. modified the milestones: d16-0, d16-1 on Jan 28, 2019
  5. removed
    vs-syncFor internal use only; creates a VSTS "mirror" issue.
    on Jun 20, 2019
  6. removed this from the d16-2 milestone on Jun 20, 2019
  7. jonathanpeppers commented on Feb 18, 2026

    @jonathanpeppers
    Member

    __TypeRegistrations is no longer used, I think this is old and can be closed.

  8. locked and limited conversation to collaborators on Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions