Skip to content

Delegate IL size regression in C# 11 #1034

@jonathanpeppers

Description

@jonathanpeppers

Context: dotnet/roslyn#62832 (comment)

On a recent .NET 7 bump, we found a ~4.5% app size regression related to a new C# 11 delegate feature. I set LangVersion=10 for now to prevent the regression: dotnet/android@938b2cb

Instead of emitting e.g.

static Delegate GetGetActionBarHandler ()
{
	if (cb_getActionBar == null)
		cb_getActionBar = JNINativeWrapper.CreateDelegate ((_JniMarshal_PP_L) n_GetActionBar);
	return cb_getActionBar;
}

generator should instead emit:

static Delegate GetGetActionBarHandler ()
{
	if (cb_getActionBar == null)
		cb_getActionBar = JNINativeWrapper.CreateDelegate (new _JniMarshal_PP_L(n_GetActionBar));
	return cb_getActionBar;
}

This should avoid a C#11 "caching method group conversion", allowing Mono.Android.dll assembly size to be ~unchanged between C#10 and C#11.

Workaround

To avoid this size regression, set LangVersion to 10 in your Android bindings project:

<LangVersion>10</LangVersion>

Android bindings projects do not use any features that require C# 11.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementProposed change to current functionalitygeneratorIssues binding a Java library (generator, class-parse, etc.)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions