bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: libtool 2.4 args parsing incredibly slow


From: Dan McGee
Subject: Re: libtool 2.4 args parsing incredibly slow
Date: Sat, 29 Jan 2011 18:04:17 -0600

On Sat, Jan 29, 2011 at 5:58 PM, Chet Ramey <chet.ramey@case.edu> wrote:
> On 1/25/11 10:08 PM, Peter O'Gorman wrote:
>> Hi,
>>
>> Dan reported a libtool performance regression in libtool-2.4 when running
>> his binaries with a large number of arguments.
>>
>> Libtool creates a shell script which usually sets some env vars and runs
>> the binary, new in recent libtool, the script also takes arguments, so
>> these have to be removed when execing the binary.
>>
>> Because forking is usually quite expensive, this shell function avoids forks:
>>
>> func_exec_program ()
>> {
>>   for lt_wr_arg
>>   do
>>     case \$lt_wr_arg in
>>     --lt-*) ;;
>>     *) set x "$@" "$lt_wr_arg"; shift;;
>>     esac
>>     shift
>>   done
>>
>>   func_exec_program_core ${1+"$@"}
>> }
>
> This is a terribly inefficient function.  You are re-evaluating "$@" for
> every argument.  (That, for various reasons, gets expensive in bash
> because of translation between different internal representations and
> increases linearly with the number of positional parameters.)
>
> Why not use what bash gives you?  Instead of reusing the positional
> parameters, use a second array.  That would allow you to use the +=
> operator, do away with the dummy `x' and shift, and pass "${array[@]}"
> to the executed function.

Probably because this is not a bash-specific script but designed to
run in any sh interpreter.

-Dan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]