[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: libtool 2.4 args parsing incredibly slow
From: |
Chet Ramey |
Subject: |
Re: libtool 2.4 args parsing incredibly slow |
Date: |
Sat, 29 Jan 2011 18:58:01 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2 |
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.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/