Re: [PATCH 05/20] scripts/make-erofs.sh: Avoid unneeded calls to dirname

Alyssa Ross
2025-09-10T20:04:33Z

[-- Attachment #1: Type: text/plain, Size: 1839 bytes --]

Demi Marie Obenour <demiobenour@gmail.com> writes:

> Use builtin string manipulation instead.
>
> Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
> ---
> scripts/make-erofs.sh | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/make-erofs.sh b/scripts/make-erofs.sh
> index cf942972910c76e1835dc5b0084c2d04bf084a9d..93cb3245f409b24c24be05e9307a1b2e12c867fe 100755
> --- a/scripts/make-erofs.sh
> +++ b/scripts/make-erofs.sh
> @@ -78,7 +78,19 @@ while read -r arg1; do
>
> check_path "$arg1" "$arg2"
>
> - parent=$(dirname "$arg2")
> + # The below simple version of dirname(1) can only handle
> + # a subset of all paths, but this subset includes all of
> + # the paths that check_path doesn't reject.
> + case $arg2 in
> + (*/*)
> + # Create the parent directory if it doesn't already
> + # exist.
> + parent=${arg2%/*}
> + ;;
> + (*)
> + parent=.
> + ;;
> + esac
> mkdir -p -- "$root/$parent"
> cp -RT -- "$arg1" "$root/$arg2"
> done

Saves about 600ms for me, and the improvement is just outside the margin
of error. What do we think? Worth it?

(6aab79a is with patches 1–3 from this series applied;
7cc01b6 is patches 1–5.)

% hyperfine -w 1 -L commit 6aab79a,7cc01b6 --prepare 'git checkout {commit} && make clean && make build/etc/s6-rc' 'make'
Benchmark 1: make (commit = 6aab79a)
Time (mean ± σ): 13.205 s ± 0.282 s [User: 2.007 s, System: 6.397 s]
Range (min … max): 12.934 s … 13.698 s 10 runs

Benchmark 2: make (commit = 7cc01b6)
Time (mean ± σ): 12.662 s ± 0.290 s [User: 1.675 s, System: 6.151 s]
Range (min … max): 12.371 s … 13.127 s 10 runs

Summary
make (commit = 7cc01b6) ran
1.04 ± 0.03 times faster than make (commit = 6aab79a)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]