Replace external dirname/basename with parameter expansion in hot loops

lidarr_missing_art.sh's album-directory-map loop (both the cache-hit and
live-fallback branches) and arr_profile_enforcer.sh's _is_kids_path()
called dirname/basename once per item -- 127K+ tracks and ~4000
series/movies respectively, each call forking a subprocess. Measured:
0.39s vs 72.2s for 20K calls, ~185x. Verified identical output against
real paths (including unicode/space/paren edge cases) before switching.
This commit is contained in:
Gmer4Lfe
2026-07-17 01:39:21 -04:00
parent 254b400caf
commit 072df6b153
2 changed files with 10 additions and 4 deletions
+5 -2
View File
@@ -104,8 +104,11 @@ exit(1);
_is_kids_path() {
local path="$1"
local dir
dir=$(basename "$(dirname "$path")")
# Parameter expansion instead of external dirname+basename — called once per series/movie
# (~4000 items combined), each call was forking two subprocesses. Measured 2026-07-17:
# ~185x faster per equivalent call (0.39s vs 72.2s per 20K) for the identical result.
local parent="${path%/*}"
local dir="${parent##*/}"
[[ "$dir" == *kids* || "$dir" == *anime* ]]
}