Skip to content

Commit

Permalink
mimalloc: avoid having to link to psapi just for mimalloc
Browse files Browse the repository at this point in the history
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 <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Sep 22, 2022
1 parent 0cf7358 commit 7c6d4ad
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions compat/mimalloc/stats.c
Expand Up @@ -459,6 +459,7 @@ mi_msecs_t _mi_clock_end(mi_msecs_t start) {
#include <windows.h>
#include <psapi.h>
#pragma comment(lib,"psapi.lib")
#include "compat/win32/lazyload.h"

static mi_msecs_t filetime_msecs(const FILETIME* ftime) {
ULARGE_INTEGER i;
Expand All @@ -479,12 +480,17 @@ static void mi_stat_process_info(mi_msecs_t* elapsed, mi_msecs_t* utime, mi_msec
*utime = filetime_msecs(&ut);
*stime = filetime_msecs(&st);
PROCESS_MEMORY_COUNTERS info;
GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
*current_rss = (size_t)info.WorkingSetSize;
*peak_rss = (size_t)info.PeakWorkingSetSize;
*current_commit = (size_t)info.PagefileUsage;
*peak_commit = (size_t)info.PeakPagefileUsage;
*page_faults = (size_t)info.PageFaultCount;
DECLARE_PROC_ADDR(psapi, BOOL, WINAPI, GetProcessMemoryInfo, HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD);
if (INIT_PROC_ADDR(GetProcessMemoryInfo)) {
GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
*current_rss = (size_t)info.WorkingSetSize;
*peak_rss = (size_t)info.PeakWorkingSetSize;
*current_commit = (size_t)info.PagefileUsage;
*peak_commit = (size_t)info.PeakPagefileUsage;
*page_faults = (size_t)info.PageFaultCount;
} else {
*current_rss = *peak_rss = *current_commit = *peak_commit = *page_faults = 0;
}
}

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

0 comments on commit 7c6d4ad

Please sign in to comment.