Skip to content

Commit 39fbe3f

Browse files
committed
mimalloc: avoid having to link to psapi just for mimalloc
Instead, load the `GetProcessMemoryInfo()` function dynamically. When needed. If needed. This is necessary because the start-up cost of Git processes spent on loading dynamic libraries is non-negligible. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent d6e6ea2 commit 39fbe3f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

compat/mimalloc/stats.c

+12-6
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ mi_msecs_t _mi_clock_end(mi_msecs_t start) {
459459
#include <windows.h>
460460
#include <psapi.h>
461461
#pragma comment(lib,"psapi.lib")
462+
#include "compat/win32/lazyload.h"
462463

463464
static mi_msecs_t filetime_msecs(const FILETIME* ftime) {
464465
ULARGE_INTEGER i;
@@ -479,12 +480,17 @@ static void mi_stat_process_info(mi_msecs_t* elapsed, mi_msecs_t* utime, mi_msec
479480
*utime = filetime_msecs(&ut);
480481
*stime = filetime_msecs(&st);
481482
PROCESS_MEMORY_COUNTERS info;
482-
GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
483-
*current_rss = (size_t)info.WorkingSetSize;
484-
*peak_rss = (size_t)info.PeakWorkingSetSize;
485-
*current_commit = (size_t)info.PagefileUsage;
486-
*peak_commit = (size_t)info.PeakPagefileUsage;
487-
*page_faults = (size_t)info.PageFaultCount;
483+
DECLARE_PROC_ADDR(psapi, BOOL, WINAPI, GetProcessMemoryInfo, HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD);
484+
if (INIT_PROC_ADDR(GetProcessMemoryInfo)) {
485+
GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
486+
*current_rss = (size_t)info.WorkingSetSize;
487+
*peak_rss = (size_t)info.PeakWorkingSetSize;
488+
*current_commit = (size_t)info.PagefileUsage;
489+
*peak_commit = (size_t)info.PeakPagefileUsage;
490+
*page_faults = (size_t)info.PageFaultCount;
491+
} else {
492+
*current_rss = *peak_rss = *current_commit = *peak_commit = *page_faults = 0;
493+
}
488494
}
489495

490496
#elif !defined(__wasi__) && (defined(__unix__) || defined(__unix) || defined(unix) || defined(__APPLE__) || defined(__HAIKU__))

0 commit comments

Comments
 (0)