1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

configure: speed up check_deps()

x4 - x25 faster.

check_deps() recursively enables/disables components, and its loop is
iterated nearly 6000 times. It's particularly slow in bash - currently
consuming more than 50% of configure runtime, and about 20% with other
shells.

This commit applies few local optimizations, most effective first:
- Use $1 $2 ... instead of pushvar/popvar, and same at enable_deep*
- Abort early in one notable case - empty deps, to avoid costly no-op.
- Smaller changes which do add up:
  - Handle ${cfg}_checking locally instead of via enable[d]/disable
  - ${cfg}_checking: test done before inprogress - x2 faster in 50%+
  - one eval instead of several at the empty-deps early abort path.

- The "actual work" part is unmodified - just its surroundings.

Biggest speedups (relative and absolute) are observed with bash.

Tested-by: Michael Niedermayer <michael@niedermayer.cc>
Tested-by: Helmut K. C. Tessarek <tessarek@evermeet.cx>
Tested-by: Dave Yeo <daveryeo@telus.net>
Tested-by: Reino Wijnsma <rwijnsma@xs4all.nl>
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
Avi Halachmi (:avih) 2018-08-05 06:16:44 +03:00 committed by James Almer
parent 923586a58f
commit 45499e557c

50
configure vendored
View File

@ -676,13 +676,10 @@ disable_sanitized(){
do_enable_deep(){ do_enable_deep(){
for var; do for var; do
enabled $var && continue enabled $var && continue
eval sel="\$${var}_select" set -- $var
eval sgs="\$${var}_suggest" eval enable_deep \$${var}_select
pushvar var sgs var=$1
enable_deep $sel eval enable_deep_weak \$${var}_suggest
popvar sgs
enable_deep_weak $sgs
popvar var
done done
} }
@ -694,9 +691,9 @@ enable_deep(){
enable_deep_weak(){ enable_deep_weak(){
for var; do for var; do
disabled $var && continue disabled $var && continue
pushvar var set -- $var
do_enable_deep $var do_enable_deep $var
popvar var var=$1
enable_weak $var enable_weak $var
done done
} }
@ -756,23 +753,31 @@ is_in(){
return 1 return 1
} }
# The cfg loop is very hot (several thousands iterations), and in bash also
# potentialy quite slow. Try to abort the iterations early, preferably without
# calling functions. 70%+ of the time cfg is already done or without deps.
check_deps(){ check_deps(){
for cfg; do for cfg; do
enabled ${cfg}_checking && die "Circular dependency for $cfg." eval [ x\$${cfg}_checking = xdone ] && continue
disabled ${cfg}_checking && continue eval [ x\$${cfg}_checking = xinprogress ] && die "Circular dependency for $cfg."
enable ${cfg}_checking
eval dep_all="\$${cfg}_deps" eval "
eval dep_any="\$${cfg}_deps_any" dep_all=\$${cfg}_deps
eval dep_con="\$${cfg}_conflict" dep_any=\$${cfg}_deps_any
eval dep_sel="\$${cfg}_select" dep_con=\$${cfg}_conflict
eval dep_sgs="\$${cfg}_suggest" dep_sel=\$${cfg}_select
eval dep_ifa="\$${cfg}_if" dep_sgs=\$${cfg}_suggest
eval dep_ifn="\$${cfg}_if_any" dep_ifa=\$${cfg}_if
dep_ifn=\$${cfg}_if_any
"
pushvar cfg dep_all dep_any dep_con dep_sel dep_sgs dep_ifa dep_ifn # most of the time here $cfg has no deps - avoid costly no-op work
if [ "$dep_all$dep_any$dep_con$dep_sel$dep_sgs$dep_ifa$dep_ifn" ]; then
eval ${cfg}_checking=inprogress
set -- $cfg "$dep_all" "$dep_any" "$dep_con" "$dep_sel" "$dep_sgs" "$dep_ifa" "$dep_ifn"
check_deps $dep_all $dep_any $dep_con $dep_sel $dep_sgs $dep_ifa $dep_ifn check_deps $dep_all $dep_any $dep_con $dep_sel $dep_sgs $dep_ifa $dep_ifn
popvar cfg dep_all dep_any dep_con dep_sel dep_sgs dep_ifa dep_ifn cfg=$1; dep_all=$2; dep_any=$3; dep_con=$4; dep_sel=$5 dep_sgs=$6; dep_ifa=$7; dep_ifn=$8
[ -n "$dep_ifa" ] && { enabled_all $dep_ifa && enable_weak $cfg; } [ -n "$dep_ifa" ] && { enabled_all $dep_ifa && enable_weak $cfg; }
[ -n "$dep_ifn" ] && { enabled_any $dep_ifn && enable_weak $cfg; } [ -n "$dep_ifn" ] && { enabled_any $dep_ifn && enable_weak $cfg; }
@ -788,8 +793,9 @@ check_deps(){
is_in $dep $LIBRARY_LIST && continue is_in $dep $LIBRARY_LIST && continue
enabled $dep && eval append ${cfg}_extralibs ${dep}_extralibs enabled $dep && eval append ${cfg}_extralibs ${dep}_extralibs
done done
fi
disable ${cfg}_checking eval ${cfg}_checking=done
done done
} }