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

[XamlC] Compile TypeTypeConverter #615

Merged
merged 1 commit into from Dec 12, 2016

Conversation

Projects
None yet
3 participants
@StephaneDelcroix
Member

StephaneDelcroix commented Dec 6, 2016

Description of Change

[XamlC] Compile TypeTypeConverter

this is a huge improvements it:

  • reduce the code size (e.g the StyleTests.InitializeComponent shrunk down to 3545 from 4104)
  • do not resolve types at runtime as it's expensive and involve reflection

there's no new tests, this is already covered

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard
  • Consolidate commits as makes sense
  • Contains a goto statement
{}Foo
</Label.Text>
</Label>
</StackLayout>

This comment has been minimized.

@StephaneDelcroix

StephaneDelcroix Dec 9, 2016

Member

this Xaml was invalid (but was working in the context of the test)

@StephaneDelcroix

StephaneDelcroix Dec 9, 2016

Member

this Xaml was invalid (but was working in the context of the test)

Show outdated Hide outdated Xamarin.Forms.Xaml.Xamlc/Xamarin.Forms.Xaml.Xamlc.csproj Outdated
@@ -4,6 +4,7 @@
namespace Xamarin.Forms
{
[Xaml.ProvideCompiled("Xamarin.Forms.Core.XamlC.TypeTypeConverter")]

This comment has been minimized.

@StephaneDelcroix

StephaneDelcroix Dec 9, 2016

Member

it references the class by name, so the Core doesn't hold a reference on the BuildTask assembly

@StephaneDelcroix

StephaneDelcroix Dec 9, 2016

Member

it references the class by name, so the Core doesn't hold a reference on the BuildTask assembly

var getTypeFromHandle = module.Import(typeof(Type).GetMethod("GetTypeFromHandle", new[] { typeof(RuntimeTypeHandle) }));
yield return Instruction.Create(OpCodes.Ldtoken, module.Import(typeRef));
yield return Instruction.Create(OpCodes.Call, module.Import(getTypeFromHandle));
yield break;

This comment has been minimized.

@StephaneDelcroix

StephaneDelcroix Dec 9, 2016

Member

for references, and understanding what's going on, this c# code

public static void Main()
{
    var a = typeof(Tests);
}

is compiled to

.method public static hidebysig 
           default void Main ()  cil managed 
    {
        // Method begins at RVA 0x2058
	.entrypoint
	// Code size 12 (0xc)
	.maxstack 1
	.locals init (
		class [mscorlib]System.Type	V_0)
	IL_0000:  ldtoken Tests
	IL_0005:  call class [mscorlib]System.Type class [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
	IL_000a:  stloc.0 
	IL_000b:  ret 
    } // end of method Tests::Main

the 2 first instructions (the 10 first bytes) is what we reproduce here

@StephaneDelcroix

StephaneDelcroix Dec 9, 2016

Member

for references, and understanding what's going on, this c# code

public static void Main()
{
    var a = typeof(Tests);
}

is compiled to

.method public static hidebysig 
           default void Main ()  cil managed 
    {
        // Method begins at RVA 0x2058
	.entrypoint
	// Code size 12 (0xc)
	.maxstack 1
	.locals init (
		class [mscorlib]System.Type	V_0)
	IL_0000:  ldtoken Tests
	IL_0005:  call class [mscorlib]System.Type class [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
	IL_000a:  stloc.0 
	IL_000b:  ret 
    } // end of method Tests::Main

the 2 first instructions (the 10 first bytes) is what we reproduce here

@StephaneDelcroix StephaneDelcroix merged commit 6112526 into master Dec 12, 2016

1 check passed

Windows-Debug-C8 Finished TeamCity Build Xamarin.Forms :: Debug :: Cycle 8 :: Windows Debug : Tests passed: 3685, ignored: 10
Details

@StephaneDelcroix StephaneDelcroix deleted the compile_typetypeconverter branch Dec 12, 2016

@samhouts samhouts added this to the 2.3.4 milestone Jun 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment