1
mirror of https://github.com/qbittorrent/qBittorrent synced 2024-10-17 13:01:11 +02:00

Work around application stuttering on Windows

This is observed by unusual high page faults when the stuttering occurs.
With this workaround, the high page faults still occurs but the GUI remains responsive.
This commit is contained in:
Chocobo1 2022-07-02 19:05:15 +08:00
parent fa26333a5b
commit ed2eadaf56
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C

View File

@ -847,6 +847,11 @@ void Application::applyMemoryPriority() const
if (!setProcessInformation) // only available on Windows >= 8
return;
using SETTHREADINFORMATION = BOOL (WINAPI *)(HANDLE, THREAD_INFORMATION_CLASS, LPVOID, DWORD);
const auto setThreadInformation = Utils::Misc::loadWinAPI<SETTHREADINFORMATION>(u"Kernel32.dll"_qs, "SetThreadInformation");
if (!setThreadInformation) // only available on Windows >= 8
return;
#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
// this dummy struct is required to compile successfully when targeting older Windows version
struct MEMORY_PRIORITY_INFORMATION
@ -883,6 +888,11 @@ void Application::applyMemoryPriority() const
break;
}
setProcessInformation(::GetCurrentProcess(), ProcessMemoryPriority, &prioInfo, sizeof(prioInfo));
// To avoid thrashing/sluggishness of the app, set "main event loop" thread to normal memory priority
// which is higher/equal than other threads
prioInfo.MemoryPriority = MEMORY_PRIORITY_NORMAL;
setThreadInformation(::GetCurrentThread(), ThreadMemoryPriority, &prioInfo, sizeof(prioInfo));
}
void Application::adjustThreadPriority() const