SystemTools: Implement GetEnv via GetEnvironmentVariableW on Win32
The GetEnvironmentVariableW
function from the Win32 API is way faster than the previously used _wgetenv
C-stdlib function.
Using this patch, CMake can configure the llvm-project codebase ~7% faster on Windows:
> hyperfine -w 1 -S 'pwsh' 'rm -r -fo build-perf; D:\dev\cpp\cmake\master\build-msvc-release\bin\cmake.exe -G Ninja -B build-perf -D CMAKE_BUILD_TYPE=Debug llvm' -n master 'rm -r -fo build-perf; D:\dev\cpp\cmake\Win32GetEnvironmentVariableW\build-msvc-release\bin\cmake.exe -G Ninja -B build-perf -D CMAKE_BUILD_TYPE=Debug llvm' -n Win32GetEnvironmentVariableW
Benchmark 1: master
Time (mean ± σ): 21.105 s ± 0.134 s [User: 0.052 s, System: 0.134 s]
Range (min … max): 20.955 s … 21.411 s 10 runs
Benchmark 2: Win32GetEnvironmentVariableW
Time (mean ± σ): 19.816 s ± 0.124 s [User: 0.049 s, System: 0.172 s]
Range (min … max): 19.646 s … 20.041 s 10 runs
Summary
Win32GetEnvironmentVariableW ran
1.07 ± 0.01 times faster than master