Hi,
Anyone got any details on the overhead of a native -> managed context switch in Mono? Namely the overhead caused by calling .NET methods/creating .NET objects using the C API.
Thanks.
Hi,
Anyone got any details on the overhead of a native -> managed context switch in Mono? Namely the overhead caused by calling .NET methods/creating .NET objects using the C API.
Thanks.
Profile, if you want or need specific details, since that's the only way you'll know whether your specific situation is fast enough...
That being said,
The Mono native API is very fast. When you create an object using Mono's C API, it's doing basically the same thing as the managed runtime when it creates the object. Calling a method is similar.
The real overhead comes in trying to pass and convert data back and forth. Just creating an object and calling a method is blazingly fast - trying to convert data through multiple types is slightly slower. However, using the C API is very fast, so unlikely to be a performance issue. (Unless, of course, you're doing this in a very tight loop, or something similar. In that case, refactor your loop into a method the managed side, and just call it once. That puts a single context switch into place.)
The current API for invoking a managed method from C code has these kinds of overhead:
We're going to introduce a new API that does away with the overhead in the first and the last points above. In the mean time, unless you're doing millions of calls per second, these overheads are pretty small and almost always dwarfed by the actual managed method called doing real work.