[XamlC] Compiled converters #358

Merged
merged 1 commit into from Sep 26, 2016

Conversation

Projects
None yet
4 participants
@StephaneDelcroix
Member

StephaneDelcroix commented Sep 15, 2016

Description of Change

Do not use the TypeConverter at runtime. Instead output the resulting code directly

so, this Xaml:

<Foo RectangleBP="4,8,16,32" BackgroundColor="Pink"/>

is compiled to this IL

IL_006d:  ldloc.1 
IL_006e:  ldsfld class [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty Xamarin.Forms.Xaml.UnitTests.CompiledTypeConverter::RectangleBPProperty
IL_0073:  ldc.r8 4.
IL_007c:  ldc.r8 8.
IL_0085:  ldc.r8 16.
IL_008e:  ldc.r8 32.
IL_0097:  newobj instance void valuetype [Xamarin.Forms.Core]Xamarin.Forms.Rectangle::'.ctor'(float64, float64, float64, float64)
IL_009c:  box [Xamarin.Forms.Core]Xamarin.Forms.Rectangle
IL_00a1:  callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.BindableObject::SetValue(class [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty, object)
IL_00a6:  ldloc.1 
IL_00a7:  ldsfld class [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty [Xamarin.Forms.Core]Xamarin.Forms.VisualElement::BackgroundColorProperty
IL_00ac:  ldsfld valuetype [Xamarin.Forms.Core]Xamarin.Forms.Color [Xamarin.Forms.Core]Xamarin.Forms.Color::Pink
IL_00b1:  box [Xamarin.Forms.Core]Xamarin.Forms.Color
IL_00b6:  callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.BindableObject::SetValue(class [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty, object)

instead of this one without the patch

IL_0076:  ldloc 1
IL_007a:  ldsfld class [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty Xamarin.Forms.Xaml.UnitTests.CompiledTypeConverter::RectangleBPProperty
IL_007f:  newobj instance void class [Xamarin.Forms.Core]Xamarin.Forms.RectangleTypeConverter::'.ctor'()
IL_0084:  ldstr "4,8,16,32"
IL_0089:  callvirt instance object class [Xamarin.Forms.Core]Xamarin.Forms.RectangleTypeConverter::ConvertFromInvariantString(string)
IL_008e:  callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.BindableObject::SetValue(class [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty, object)
IL_0093:  ldloc 1

IL_0097:  ldsfld class [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty [Xamarin.Forms.Core]Xamarin.Forms.VisualElement::BackgroundColorProperty
IL_009c:  newobj instance void class [Xamarin.Forms.Core]Xamarin.Forms.ColorTypeConverter::'.ctor'()
IL_00a1:  ldstr "Pink"
IL_00a6:  callvirt instance object class [Xamarin.Forms.Core]Xamarin.Forms.ColorTypeConverter::ConvertFromInvariantString(string)
IL_00ab:  callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.BindableObject::SetValue(class [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty, object)

Bugs Fixed

None, but this should provide a measurable speed gain, and huge reduction of the amount of IL generated, in most case, especially when compiling Styles or anything that depends on an IExtendedTypeConverter

API Changes

Behavioral Changes

if any, you know how to reach me

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

@jassmith jassmith merged commit 55f0665 into master Sep 26, 2016

3 of 5 checks passed

Android-UITests Finished TeamCity Build Xamarin.Forms :: Debug :: Cycle8 :: UI Tests :: OSX Test Cloud Package - Run Android 6.0.1 : Exit code 255
Details
iOS10-UITests Finished TeamCity Build Xamarin.Forms :: Debug :: Cycle8 :: UI Tests :: OSX Test Cloud Package - Run iOS Unified iOS10 : Tests failed: 4, …
Details
OSX-Debug-C8 Finished TeamCity Build Xamarin.Forms :: Debug :: Cycle8 :: OSX Debug : Running
Details
Windows-Debug-C8 Finished TeamCity Build Xamarin.Forms :: Debug :: Cycle8 :: Windows Debug : Tests passed: 3454, ignored: 8
Details
iOS9-UITests Finished TeamCity Build Xamarin.Forms :: Debug :: Cycle8 :: UI Tests :: OSX Test Cloud Package - Run iOS Unified iOS9 : Tests passed: 342,…
Details

@StephaneDelcroix StephaneDelcroix deleted the xamlc-compiledconverters branch Jan 31, 2017

@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