Note that there are some explanatory texts on larger screens.

plurals
  1. POReducing the cost of native <-> managed interactions in monotouch
    text
    copied!<p>I'm playing with a native library for which I wrote monotouch (are we supposed to name that Xamarin.iOS now?) bindings.</p> <p>Overriding some often used methods in C# shows a severe performance downgrade, even if the core of the function do nothing or return base.X (). Instruments confirms the problem and the time spend in managed&lt;->native interactions.</p> <p>Is there a way to speed that up, from one side or the other (native or managed) ? Or is this a tax to pay when P/Invoking in MT ?</p> <p>The glass ceiling I'm hitting is about 50000 calls/sec. </p> <p><strong>[UPDATE 2013/02/22]</strong> To give some context or example, here's what I'm doing. I'm playing with cocos2d kinematics (without chipmunk). To manage my own position of sprites, I have to override</p> <pre><code>CGAffineTransform NodeToParentTransform { get; } </code></pre> <p>and </p> <pre><code>bool Dirty { get; } </code></pre> <p>The former returns a matrices, and poke the native side to get parameters like ScaleX, ScaleY, RotationX. RotationY and AnchorPointInPoints, the latter return <code>true</code> unconditionally.</p> <p>My attempt in reducing the cost is partly successful at this moment as, by changing the native code to have a single point to override which doesn't poke to any properties, I get a 25% to 50% speedup.</p> <pre><code>-(BOOL) dirty:(CGAffineTransform*)nodeToParentTransform rotationX:(float)rotX rotationY:(float)rotY scaleX:(float)scaleX scaleY:(float)scaleY anchorPointInPoints:(CGPoint)anchorPointInPoints; </code></pre> <p>I'm now getting an almost acceptable 25-30fps for my 3500 sprites, but I'd still like to go further. And also not have to patch the native sources.</p> <p><strong>[UPDATE 2013/02/22 2]</strong> Here's a sample that you could use to test <a href="https://github.com/StephaneDelcroix/mt-speed" rel="nofollow noreferrer">https://github.com/StephaneDelcroix/mt-speed</a>. It contains an over simplified first order kinematic engine, 3501 bodies and sprites.</p> <p>The interesting class here is <code>KinematicSprite</code>. The code as is works on a modified version of cocos2d (included in Cocos2D.dll). You can make it work on stock cocos2d and cocos2d bindings by commenting out the new <code>Dirty</code> function and uncommenting <code>NodeToParentTransform</code> and the old <code>Dirty</code>. As per <a href="https://stackoverflow.com/questions/14962741/subclassing-bound-type-in-mono-touch">Subclassing bound type in mono touch</a>, it only works on devices. I get 20 to 22.5 fps on an iPad mini.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload