result-pattern is less than 2x faster name-ref-functions.

See benchmark below (however, for all typical usage name-ref-functions should be preferred as it’s plenty faster than process substitution).

GT-Sandbox-Snapshot

Code

foo() {
  local -n some_local_name="${1:?name of external variable}"
  some_local_name=42
}
 
bar() {
  some_global_result=42
}
 
time_name_ref() {
  local var1
  for i in {1..10000} ; do
    foo var1
  done
}
 
time_result_pattern(){
  local var1
  for i in {1..10000} ; do
    bar
    var1="${some_global_result:?}"
  done
}
 
main() {
  # Warmup
  for i in {1..100}; do
    foo var1
    bar
  done
 
 time time_name_ref
 time time_result_pattern
}
 
main "${@}" || exit 1

Command to reproduce:

gt.sandbox.checkout.commit 30e75e51081941dc1e99 \
&& cd "${GT_SANDBOX_REPO}/bash" \
&& cmd.run.announce "./main.sh"

Recorded output of command:

 
real	0m0.053s
user	0m0.053s
sys	0m0.000s
 
real	0m0.035s
user	0m0.035s
sys	0m0.000s