[Mono-dev] Fast variant type cast

Rodrigo Kumpera kumpera at gmail.com
Sun Sep 26 17:03:05 EDT 2010


An update on the branch.

I fixed caching under gsharing and made detection more usable. I also added
a negative cache to isinst
which translated into big hit-ratio (99%) for test suites workload.

I'd like your opinion on this approach before I go forward into making it
faster by making wrappers.

Cheers,
Rodrigo



On Fri, Sep 24, 2010 at 7:21 PM, Rodrigo Kumpera <kumpera at gmail.com> wrote:

> Hey Mark and Paolo,
>
> I've speed some time looking into speeding up variant type cast as one can
> expect it to be used a lot more with 4.0
> since a lot of central types have been made variant.
>
> I first looked into making a managed version of the casting code for
> variant types but this is incredibly hard, to say the least,
> due to 2 issues, it has to inspect the instantiation vector of the target
> type (which is made of MonoType values) and it has
> to iterate thru all interfaces of a given type.
>
> It is not impossible, but it's a lot work and probably quite some extra
> memory to make it fast.
>
> So I decided to avoid the whole problem and go with adding an one entry
> cache in front of the casting op. It's significantly faster
> when the hit ratio is high and the cache test could be inlined for extra
> performance (right now it's an icall).
>
> I got this working on on this branch of github:
> http://github.com/kumpera/mono/commits/fast_variant_cast
>
> Then I went into checking real world usefulness and found out that this
> change does no good at all. At least with the benchmarks
> I selected.
>
> IronPython does a constant number of casting operations, so it's not
> usable.
> The test suites of corlib and sys.core revealed one critical bug with my
> approach, it doesn't handle the case where it's not
> possible to statically known if we're handling with a generic variant type
> or not. And this is 99.999% of all casts to variant types
> on those tests.
>
> So this left me with two options. Make mono_object_isinst faster with
> variant types or look into caching all casts ops
> under gsharing.
>
> I'll try enabling caching for all gshared cast ops first, then into making
> mono_object_isinst faster if needed. How to do
> it still an open problem but looks easy for types without nested variance -
> not IEnumerable<Func<string,string>> for example.
>
>
> I tried to enable caching for all gshared casts but I'm bumping into a
> runtime crash in the innards of the gsharing code.
>
> Any advices, tips or a code review of the mentioned branch?
>
> Cheers,
> Rodrigo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100926/53b34973/attachment.html 


More information about the Mono-devel-list mailing list