Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by FireFlyD · Sep 25, 2018 at 01:46 AM · buildperformancedllc++

What could cause C++ dll muti-threading to perform worse in Build mode

I am writing a C++ DLL for my Unity Windows application, where the dll will create multiple work-intense and time-critical threads. One surprising behaviour I observed was that the performance of the DLL was significantly worse in Build mode than Editor mode. To rule out the possibility that my function is affecting the performance, I did an experiment where I replaced my function with std::this_thread::sleep_for(std::chrono::milliseconds(30)) and logged down the execution time. When in the Editor mode, the execution time was very consistently around 30 ms as expected. I ran the editor session for a long time to make sure the time measurement is consistent. However, when in the Build, I could always observe some sort of "hiccup" from time to time that the abnormal execution time can range from 35 ms to 45 ms. I allocated a console window to display the standard output from the DLL in both Editor and Build mode.

Here is the pseudo code of my DLL:

 void initialize(std::thread *& pWorkerThread, [other_args]) {
     pWorkerThread = new std::thread(WorkerFunction);
     // Initialize other threads ...
 } 
 
 void stop(std::thread *& pWorkerThread, [other_args]) {
     // set stop_condition here

     if (pWorkerThread->joinable()) {
          pWorkerThread->join();
     }
     delete pWorkerThread;
     pWorkerThread = NULL;
 }
 
 void WorkerFunction() {
     while (!stop_condition) {
         std::chrono::steady_clock::time_point t_start = std::chrono::steady_clock::now();
 
         // simulate the work load
         std::this_thread::sleep_for(std::chrono::milliseconds(30));

         std::chrono::steady_clock::time_point t_end = std::chrono::steady_clock::now();
         std::chrono::duration<float, std::milli> dur = t_end - t_start;
         std::cout << "Process duration: " << dur.count() << std::endl;
     }
 }

Since the editor is adding a lot of overhead, one would typically assume the performance is worse in Editor mode. In addition, since my c++ functions are built into the DLL, based on my understanding, they should behave the same regardless of which mode my Unity application calls them. I was suspecting the process and thread priority might be different in Build mode, so I manually set the priority class of my application to High_PRIORITY_CLASS using WinAPI, but it did not improve the situation at all. At this point, I have been stuck on this for days and I am running out of ideas for how this could happen and what to do. If someone could point out potential topics I should look at, or explain what are the differences between build and editor mode that could result in such performance issue, I would greatly appreciate it!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

113 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I get maximum performance on extremely heavy calculations? 1 Answer

Distribute terrain in zones 3 Answers

Native c++ (mingw) plugin works in editor but not in build 1 Answer

How to build a game with Leap Motion ? 1 Answer

RunTime Error in Unity when I'm using a function from a C++ Dll 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges