开发者

Can somebody explain any CLR / DLR subclass overheads?

If I have a library written using CLR compliant code (i.e. in C#) and I subclass some of those classes using the DLR (i.e. in IronPython) does this have any effect on the speed of my CLR library (i.e. casting etc) compared to if it were subclassed using only CLR compliant code?

I'm hoping the answer is 'no' as long as the DLR does not override any of the code required my my CLR library. I can write some code to empirically benchmark the answer but wondered if any of you knew.

Thank you v开发者_StackOverflow中文版ery much and happy new year!

John


There's no overhead added in your library code at all. Introducing the new subclasses won't alter the behavior of the CLR at all. You could imagine a version of the CLR that does Class Hierarchy Analysis or runtime optimizations which inline methods or optimize away casts where the presence of additional subclasses could default those optimizations. But I don't know of any CLR implementations which do those optimizations (certainly the MS CLR does not).

But working with the Python subclasses could be a little slower. That's because the Python subclass will override all of the virtual members - those overrides will then need to dispatch to the Python function implementing the overload or to the base class. So whenever you're working with an object subclassed in Python it will be a little slower on calls to virtual methods. The extra overhead will consist of one or more dictionary lookups into the Python type object to see if the method is implemented there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜