cache processFromHandle and threadFromHandle (14k events/s -> 20k events/s)

This commit is contained in:
mrexodia 2017-06-30 14:41:13 +02:00
parent 7a4d0b2ff4
commit 7da59f841d
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
1 changed files with 38 additions and 14 deletions

View File

@ -48,6 +48,8 @@ public:
void DebugLoop() void DebugLoop()
{ {
processFromHandleCache.clear();
threadFromHandleCache.clear();
Start(); Start();
} }
@ -775,7 +777,14 @@ private: //functions
} }
} }
std::unordered_map<HANDLE, Thread*> threadFromHandleCache;
Thread* threadFromHandle(HANDLE hThread) Thread* threadFromHandle(HANDLE hThread)
{
auto found = threadFromHandleCache.find(hThread);
if(found != threadFromHandleCache.end())
return found->second;
auto result = [this, hThread]() -> Thread*
{ {
THREAD_BASIC_INFORMATION tbi; THREAD_BASIC_INFORMATION tbi;
if(!getThreadInfo(hThread, tbi)) if(!getThreadInfo(hThread, tbi))
@ -787,14 +796,29 @@ private: //functions
if(foundT == foundP->second->threads.end()) if(foundT == foundP->second->threads.end())
return nullptr; return nullptr;
return foundT->second.get(); return foundT->second.get();
}();
if(result)
threadFromHandleCache[hThread] = result;
return result;
} }
std::unordered_map<HANDLE, Process*> processFromHandleCache;
Process* processFromHandle(HANDLE hProcess) Process* processFromHandle(HANDLE hProcess)
{
auto found = processFromHandleCache.find(hProcess);
if(found != processFromHandleCache.end())
return found->second;
auto result = [this, hProcess]() -> Process*
{ {
auto foundP = mProcesses.find(GetProcessId(hProcess)); auto foundP = mProcesses.find(GetProcessId(hProcess));
if(foundP == mProcesses.end()) if(foundP == mProcesses.end())
return nullptr; return nullptr;
return foundP->second.get(); return foundP->second.get();
}();
if(result)
processFromHandleCache[hProcess] = result;
return result;
} }
static HardwareType hwtypeFromTitan(DWORD type) static HardwareType hwtypeFromTitan(DWORD type)