- Home /
DLL calls (Plugins) way slower within Unity
Hello,
I am facing dramatic slow down of my code when using calls to dll form the Plugins folder.
Here is the test I have done:
My code is compiled in a bunch of C# and C++ dlls. C++ dlls are native and called within the C# code through specific wrappers.
First test I do is outside Unity: in a dedicated C# console project, I call and measure the performance of the C#/C++ dll. It works fine and runs fast as it should.
Second test I do is inside Unity. I drop my dlls in the Plugins folder and write an identical test within a MonoBehaviour attached to an empty GameObject in a empty scene. The test runs then about 20 times slower.
I wonder why I see the slow down when using the code though dlls. Is there any different behaviors between direct calls within a dedicated C# project or within Unity ? I did not find any relevant answers so far when Googling the topic.
Thanks for your help!
$$anonymous$$y initial test was in the editor. Indeed I get the speeds back when running the test after building the project. I will try it with Unity 2018 to make sure it perform well with this version as well.
Thanks for your quick answer.
You are welcome!
I also use some DLLs written in C/C++, and also noticed the performance decrease. Fortunately, it almost completely disappears in builds.
Answer by Harinezumi · Apr 24, 2018 at 08:14 AM
Did you do the second test running in the Editor, or did you make a build? The Editor does have a significant overhead, so that could explain the slowdown. Builds are usually a lot faster than running in the Editor. Then again, the reason can be something else as well.
Another possibility is the C#/.Net version: Unity has its custom subset, based on a quite outdated version. Supposedly C# 7 will be supported starting with Unity 2018.1.
I just did a test where I was getting 3 fps inside the editor using native dll calls. in the build i was getting 140 fps... Using the equivalent c# source code, I was getting 60 fps in editor and in build. Thanks for mentioning this otherwise I would have never tested!!
Your answer
Follow this Question
Related Questions
How do I use two different versions of a .dll in one project 0 Answers
How to link to scripts in the Package Manager when building a dll. 0 Answers
How to use the Windows.Gaming.Input namespace in a windows standalone build? 0 Answers
Unity XR plugin manager Tries to load oculus dll on windows even if its disabled. 0 Answers
How do I get maximum performance on extremely heavy calculations? 1 Answer