I am pretty new to Unity, but I am finding that my native code is running really slowly when called from Unity. When I call the same native code from other apps not running Unity, it runs fine.
Are there any typical gotchas here? I am struggling to understand why my native c++ code runs so slow when using Unity. Also, is there any notion of debug / release when running through the editor?
There is an overhead in calling plugin code from Mono scripts. If you make lots of separate calls to a native code function then this overhead might start to mount up. If this might be causing the slowdown then reducing the number of individual calls would help (eg, by reimplementing the whole loop in which the function is called in native code).
I am only making a couple of calls but the native code that I call is quite computationally expensive. However, it does run just fine on both android and pc if I am running it not through Unity. This leads me to believe that Unity may well be doing something to my native code that causes it to run much more slowly when being called by Unity.