Implementing IsAssignableFrom dispatching

6 views
Skip to first unread message

damien

unread,
Mar 27, 2008, 2:33:50 PM3/27/08
to retlang-dev
I implemented something like this about 5 years ago, in C# 1.0.

For speed, you might want to cache the (from-type, to-type) pairs that
match.

Theres only a finite amount of types in an application, and a small
number of types that will be tested against each other, so the cache
will be small.

In my case, I was dispatching on multiple types passed as arguments -
basically looking for functions of the same name that could accept a
given set of arguments. You can imagine that querying IsAssignableFrom
on multiple arguments and multiple functions would be quite slow.

There might be stuff in the new dynamic language runtime that would be
usefull here.

Mike Rettig

unread,
Mar 27, 2008, 5:23:04 PM3/27/08
to retla...@googlegroups.com
Retlang no longer uses IsAssignableFrom due to the very performance implications you mention. 

The new implementation uses generics.
  public bool CanCastTo<T>()
{
return _obj is T;
}

This change made a noticeable performance improvement.  With this change and a few others, I've measured messaging rates over 4 million messages per second on a 3.0 ghz quad core running .NET 2.0.

Thanks for the feedback.

Mike
Reply all
Reply to author
Forward
0 new messages