Skip to content

Commit

Permalink
Performance updates
Browse files Browse the repository at this point in the history
 - Added performance Tests
 - Increased tupler performance better than fsharp.reflection
 - slightly increased caching performance
 - added in dynamic TypeConverter reference (not working)
  • Loading branch information
jbtule committed Jun 1, 2013
1 parent 42abbe0 commit 554a5b2
Show file tree
Hide file tree
Showing 13 changed files with 1,086 additions and 171 deletions.
8 changes: 4 additions & 4 deletions Dynamitey/CacheableInvocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,21 +256,21 @@ public override object Invoke(object target, params object[] args)
Dynamic.InvokeSetIndex(target, args);
return null;
case InvocationKind.InvokeMember:
return InvokeHelper.InvokeMemberCallSite(target, Name, args, _argNames, _context, _staticContext, ref _callSite);
return InvokeHelper.InvokeMemberCallSite(target, (InvokeMemberName) Name, args, _argNames, _context, _staticContext, ref _callSite);
case InvocationKind.InvokeMemberAction:
InvokeHelper.InvokeMemberActionCallSite(target, Name, args, _argNames, _context, _staticContext, ref _callSite);
InvokeHelper.InvokeMemberActionCallSite(target, (InvokeMemberName)Name, args, _argNames, _context, _staticContext, ref _callSite);
return null;
case InvocationKind.InvokeMemberUnknown:
{

try
{
var tObj = InvokeHelper.InvokeMemberCallSite(target, Name, args, _argNames, _context, _staticContext, ref _callSite);
var tObj = InvokeHelper.InvokeMemberCallSite(target, (InvokeMemberName)Name, args, _argNames, _context, _staticContext, ref _callSite);
return tObj;
}
catch (RuntimeBinderException)
{
InvokeHelper.InvokeMemberActionCallSite(target, Name, args, _argNames, _context, _staticContext, ref _callSite2);
InvokeHelper.InvokeMemberActionCallSite(target, (InvokeMemberName)Name, args, _argNames, _context, _staticContext, ref _callSite2);
return null;

}
Expand Down
12 changes: 5 additions & 7 deletions Dynamitey/Dynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static CallSite CreateCallSite(Type delegateType, CallSiteBinder binder,
bool isEvent = false)
{

return InvokeHelper.CreateCallSite(delegateType, binder.GetType(), InvokeHelper.Unknown, () => binder, name, context, argNames,
return InvokeHelper.CreateCallSite(delegateType, binder.GetType(), InvokeHelper.Unknown, () => binder, (InvokeMemberName)name, context, argNames,
staticContext,
isEvent);
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public static CallSite<T> CreateCallSite<T>(CallSiteBinder binder, String_OR_Inv
string[] argNames = null, bool staticContext = false,
bool isEvent = false) where T : class
{
return InvokeHelper.CreateCallSite<T>(binder.GetType(), InvokeHelper.Unknown, () => binder, name, context, argNames, staticContext,
return InvokeHelper.CreateCallSite<T>(binder.GetType(), InvokeHelper.Unknown, () => binder, (InvokeMemberName) name, context, argNames, staticContext,
isEvent);
}

Expand Down Expand Up @@ -170,7 +170,7 @@ public static dynamic InvokeMember(object target, String_OR_InvokeMemberName nam
args = Util.GetArgsAndNames(args, out tArgNames);
CallSite tCallSite = null;

return InvokeHelper.InvokeMemberCallSite(target, name, args, tArgNames, tContext, tStaticContext,
return InvokeHelper.InvokeMemberCallSite(target, (InvokeMemberName)name, args, tArgNames, tContext, tStaticContext,
ref tCallSite);
}

Expand Down Expand Up @@ -383,7 +383,7 @@ public static void InvokeMemberAction(object target, String_OR_InvokeMemberName
args = Util.GetArgsAndNames(args, out tArgNames);

CallSite tCallSite = null;
InvokeHelper.InvokeMemberActionCallSite(target, name, args, tArgNames, tContext, tStaticContext,
InvokeHelper.InvokeMemberActionCallSite(target, (InvokeMemberName)name, args, tArgNames, tContext, tStaticContext,
ref tCallSite);
}

Expand Down Expand Up @@ -552,9 +552,7 @@ public static dynamic InvokeGet(object target, string name)
{
Type tContext;
bool tStaticContext;
target = target.GetTargetContext(out tContext, out tStaticContext);
tContext = tContext.FixContext();
CallSite tSite = null;
target = target.GetTargetContext(out tContext, out tStaticContext); CallSite tSite = null;
return InvokeHelper.InvokeGetCallSite(target, name, tContext, tStaticContext, ref tSite);
}

Expand Down
77 changes: 57 additions & 20 deletions Dynamitey/Internal/Optimization/BinderHash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,49 @@ internal class BinderHash
{


protected BinderHash(Type delegateType, String_OR_InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent, bool knownBinder)
protected BinderHash(Type delegateType, String name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent, bool knownBinder)
{
KnownBinder = knownBinder;
BinderType = binderType;
StaticContext = staticContext;
DelegateType = delegateType;
Name = name;
IsSpecialName = false;
GenericArgs = null;
Context = context;
ArgNames = argNames;
IsEvent = isEvent;


}



public static BinderHash Create(Type delType, String_OR_InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent, bool knownBinder)
protected BinderHash(Type delegateType, InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent, bool knownBinder)
{
return new BinderHash(delType, name, context, argNames, binderType, staticContext, isEvent, knownBinder);
KnownBinder = knownBinder;
BinderType = binderType;
StaticContext = staticContext;
DelegateType = delegateType;
Name = name.Name;
IsSpecialName = name.IsSpecialName;
GenericArgs = name.GenericArgs;
Context = context;
ArgNames = argNames;
IsEvent = isEvent;


}




public bool KnownBinder { get; protected set; }
public Type BinderType { get; protected set; }
public bool StaticContext { get; protected set; }
public bool IsEvent { get; protected set; }
public Type DelegateType { get; protected set; }
public String_OR_InvokeMemberName Name { get; protected set; }
public string Name { get; protected set; }
public bool IsSpecialName { get; protected set; }
public Type[] GenericArgs { get; protected set; }
public Type Context { get; protected set; }
public string[] ArgNames { get; protected set; }

Expand All @@ -60,6 +77,8 @@ public virtual bool Equals(BinderHash other)

var tArgNames = ArgNames;
var tOtherArgNames = other.ArgNames;
var tGenArgs = GenericArgs;
var tOtherGenArgs = other.GenericArgs;

return
!(tOtherArgNames == null ^ tArgNames == null)
Expand All @@ -69,6 +88,13 @@ public virtual bool Equals(BinderHash other)
&& (KnownBinder || Equals(other.BinderType, BinderType))
&& Equals(other.DelegateType, DelegateType)
&& Equals(other.Name, Name)
&& !(other.IsSpecialName ^ IsSpecialName)
&& !(tOtherGenArgs == null ^ tGenArgs == null)
&& (tGenArgs == null ||
//Exclusive Or makes sure this doesn't happen
// ReSharper disable AssignNullToNotNullAttribute
tGenArgs.SequenceEqual(tOtherGenArgs))
// ReSharper restore AssignNullToNotNullAttribute
&& (tArgNames == null
// ReSharper disable AssignNullToNotNullAttribute
//Exclusive Or Makes Sure this doesn't happen
Expand All @@ -94,57 +120,68 @@ public override int GetHashCode()

int result = (tArgNames == null ? 0 : tArgNames.Length * 397);
result = (result ^ StaticContext.GetHashCode());
result = (result * 397) ^ DelegateType.GetHashCode();
result = (result * 397) ^ Context.GetHashCode();
//result = (result * 397) ^ DelegateType.GetHashCode();
//result = (result * 397) ^ Context.GetHashCode();
result = (result * 397) ^ Name.GetHashCode();
return result;
}
}
}

internal class GenericBinderHashBase : BinderHash


internal class BinderHash<T> : BinderHash where T : class
{
protected GenericBinderHashBase(Type delegateType, String_OR_InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent, bool knownBinder)
: base(delegateType, name, context, argNames, binderType, staticContext, isEvent, knownBinder)
public static BinderHash<T> Create(string name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent, bool knownBinder)
{
return new BinderHash<T>(name, context, argNames, binderType, staticContext, isEvent, knownBinder);
}
}

internal class BinderHash<T> : GenericBinderHashBase where T : class
{

public static BinderHash<T> Create(String_OR_InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent, bool knownBinder)
public static BinderHash<T> Create(InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent, bool knownBinder)
{
return new BinderHash<T>(name, context, argNames, binderType, staticContext, isEvent, knownBinder);
}

protected BinderHash(String_OR_InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent,bool knownBinder)
protected BinderHash(InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent,bool knownBinder)
: base(typeof(T), name, context, argNames, binderType, staticContext, isEvent,knownBinder)
{
}

protected BinderHash(string name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent, bool knownBinder)
: base(typeof(T), name, context, argNames, binderType, staticContext, isEvent, knownBinder)
{
}

public override bool Equals(BinderHash other)
{
if (other is GenericBinderHashBase)
{

if (other is BinderHash<T>)
{
var tGenArgs = GenericArgs;
var tOtherGenArgs = other.GenericArgs;

return
!(other.ArgNames == null ^ ArgNames == null)
&& other.IsEvent == IsEvent
&& other.StaticContext == StaticContext
&& (KnownBinder || Equals(other.BinderType, BinderType))
&& Equals(other.Context, Context)
&& Equals(other.Name, Name)
&& !(other.IsSpecialName ^ IsSpecialName)
&& !(tOtherGenArgs == null ^ tGenArgs == null)
&& (tGenArgs == null ||
//Exclusive Or makes sure this doesn't happen
// ReSharper disable AssignNullToNotNullAttribute
tGenArgs.SequenceEqual(tOtherGenArgs))
// ReSharper restore AssignNullToNotNullAttribute
&& (ArgNames == null
// ReSharper disable AssignNullToNotNullAttribute
//Exclusive Or Makes Sure this doesn't happen
|| other.ArgNames.SequenceEqual(ArgNames));
// ReSharper restore AssignNullToNotNullAttribute
}
return false;
}

return base.Equals(other);
}
}
Expand Down
Loading

0 comments on commit 554a5b2

Please sign in to comment.