Skip to content

Commit 1132ba9

Browse files
committed
perf(check_os): cache uname result to eliminate repeated subprocess forks
Call uname once at source time and reuse the cached value in all OS detection functions. This eliminates up to 3 subprocess forks per bashunit::parallel::is_enabled call across the runner hot path.
1 parent 8a9bf94 commit 1132ba9

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/check_os.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ _BASHUNIT_OS="Unknown"
55
_BASHUNIT_DISTRO="Unknown"
66

77
function bashunit::check_os::init() {
8+
_BASHUNIT_UNAME="$(uname)"
89
if bashunit::check_os::is_linux; then
910
_BASHUNIT_OS="Linux"
1011
if bashunit::check_os::is_ubuntu; then
@@ -39,16 +40,18 @@ function bashunit::check_os::is_nixos() {
3940
grep -q '^ID=nixos' /etc/os-release 2>/dev/null
4041
}
4142

43+
_BASHUNIT_UNAME="$(uname)"
44+
4245
function bashunit::check_os::is_linux() {
43-
[[ "$(uname)" == "Linux" ]]
46+
[[ "$_BASHUNIT_UNAME" == "Linux" ]]
4447
}
4548

4649
function bashunit::check_os::is_macos() {
47-
[[ "$(uname)" == "Darwin" ]]
50+
[[ "$_BASHUNIT_UNAME" == "Darwin" ]]
4851
}
4952

5053
function bashunit::check_os::is_windows() {
51-
case "$(uname)" in
54+
case "$_BASHUNIT_UNAME" in
5255
*MINGW* | *MSYS* | *CYGWIN*)
5356
return 0
5457
;;

0 commit comments

Comments
 (0)