c++performancewinapidllloadlibrary

Dll unloading causing loading application major performance drop


I work for a company that develops its own game-engine. One of its features is to dynamically load and unload dlls (plugins). I've noticed a weird behavior whenever my process frees a specific dll - which results in significant performance drop. I've tried countless attempts to identify what's causing the issues (see below), but nothing seems to work. ChatGPT suggestions were useless, and I don't know what do to from here.

Full details:

Here's what I already tried:

The only thing that worked was if I loaded the dll using: LoadLibraryEx given the flag: LOAD_LIBRARY_AS_IMAGE_RESOURCE, but this isn't very helpful, since the global and static variables are not initialized in this case.

I read suggestions that this could be TLS related - I tried finding all places with relevant code and remove it. What I didn't do:

At this point I'm lost, I would appreciate and suggestions, tools, ideas.


Solution

  • After basically removing all possible chunks of code from our implementation - it turned out that we had a (stupid) wrapper class that wraps MFCLeakReport class.

    In it, there were calls to _CrtSetReportHook. Removing these calls completely solved the issue. As for why this was there for my company, or how to implement it correctly is irrelevant for the solution - but if anyone ever encounters similar behavior - try looking for MFC hooks.