Sunday, May 11, 2008

Compiled Type Optimization

I was going through the Compiled Type system and was irritated because the system auto-loaded every member, always, whenever you merely accessed the property associated to them.

For example, if I have a reference to Console, if I accessed its 'Properties'; before, it would load all the properties (which is fine) and then encapsulate every member with the framework's equivalent. While that's fine, it might make more sense to load the MemberInfo relative to the properties, and only instantiate the wrapper classes when they're called for. So that's exactly what I did.

The example below:

ICompiledClassType console = typeof(Console).GetTypeReference<ICompiledClassType>();
ITypeReferenceExpression itre = console.GetTypeExpression();
IMethodInvokeExpression imie = itre.GetMethod("WriteLine").Invoke((ExpressionBase)"Console Dimensions: ({0}, {1})", itre.GetProperty("WindowWidth"), itre.GetProperty("WindowHeight"));
IType readKeyResult = imie.ForwardType;
IMethodInvokeExpression imie2 = itre.GetMethod("ReadKey").Invoke((ExpressionBase)true);
IType readKeyResult2 = imie2.ForwardType;

When 'ForwardType' on a given expression is accessed, it auto-links the expression and any sub-expressions that are dependent upon it.

In the case above, IMethodInvokeExpression imie = . . . properly resolves to 'String' and 'Int32', 'Int32', and accordingly links to the associated member:
void Console.WriteLine(System.String, System.Object, System.Object)

The reason such indirect and lengthy optimizations are important, is if you're dealing in very large scale code generation, if it instantiated a property instance for all of the Console's properties to access its WindowWidth property, then things would suddenly start to take a long time.

As for the actual linking of methods, there wasn't really that much that could be done. In order to properly perform the lookups I went ahead and used the framework I put in place. It still does the on-access instantiation, but the iterative nature of the filtering methods ends up loading all of the elements anyway, to ensure the most accurate match is provided.

1 comment:

Anonymous said...

"Digital slot machines are programmed to have a sure proportion of payouts. And digital slot video games use a Random Number Generator to find out} finish result} of each spin," Good tellsBest Life. "You know the way you get individuals younger to gamble? Hand them a fucking phone."The industry seems to be engaged on the same hunch. In 2011, Caesar’s acquired Playtika, an internet on line casino video games company that provides free and paid mobile video games. A year later, IGT acquired the free on line casino video games app DoubleDown, which runs as both a stand-alone mobile app and thru Facebook. The company now 1xbet korea offers online desk video games and a good sample of its portfolio of slots, together with Wheel of Fortune, to mobile gamers.