diff options
author | Mike Frysinger <vapier@gentoo.org> | 2012-05-11 12:36:22 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2012-05-12 00:09:34 -0400 |
commit | 76939c46aa2817bdbcea703432c52e5aa04160f9 (patch) | |
tree | 561409f067c048780846c069e836f69710e92bda /bin/ebuild-helpers/ecompressdir | |
parent | 0098ee7395e2c9b35471a5c088eef1fa59946912 (diff) | |
download | portage-76939c46aa2817bdbcea703432c52e5aa04160f9.tar.gz portage-76939c46aa2817bdbcea703432c52e5aa04160f9.tar.bz2 portage-76939c46aa2817bdbcea703432c52e5aa04160f9.zip |
prepstrip/ecompressdir: parallelize operations
Stealing some ideas from ferringb, add a new API for doing parallel
processing in bash, and then deploy this with the stripping and
compressing stages.
For stripping coreutils which has about 100 ELFs, this brings time
to strip down from ~7 seconds to ~0.7 seconds on my system.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'bin/ebuild-helpers/ecompressdir')
-rwxr-xr-x | bin/ebuild-helpers/ecompressdir | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/bin/ebuild-helpers/ecompressdir b/bin/ebuild-helpers/ecompressdir index 17ecd8082..a2c9e52a0 100755 --- a/bin/ebuild-helpers/ecompressdir +++ b/bin/ebuild-helpers/ecompressdir @@ -2,7 +2,7 @@ # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh +source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/helper-functions.sh if [[ -z $1 ]] ; then helpers_die "${0##*/}: at least one argument needed" @@ -116,6 +116,16 @@ ret=0 rm -rf "${T}"/ecompress-skip +decompressors=( + ".Z" "gunzip -f" + ".gz" "gunzip -f" + ".bz2" "bunzip2 -f" + ".xz" "unxz -f" + ".lzma" "unxz -f" +) + +multijob_init + for dir in "$@" ; do dir=${dir#/} dir="${ED}${dir}" @@ -136,14 +146,26 @@ for dir in "$@" ; do find "${dir}" -type f -name '*.ecompress.file' -print0 | ${XARGS} -0 rm -f # not uncommon for packages to compress doc files themselves - funk_up_dir "decompress" ".Z" "gunzip -f" - funk_up_dir "decompress" ".gz" "gunzip -f" - funk_up_dir "decompress" ".bz2" "bunzip2 -f" + for (( d = 0; d < ${#decompressors[@]}; d += 2 )) ; do + # It's faster to parallelize at this stage than to try to + # parallelize the compressors. This is because the find|xargs + # ends up launching less compressors overall, so the overhead + # of forking children ends up dominating. + ( + multijob_child_init + funk_up_dir "decompress" "${decompressors[i]}" "${decompressors[i+1]}" + ) & + multijob_post_fork + : $(( ret |= $? )) + done # forcibly break all hard links as some compressors whine about it find "${dir}" -type f -links +1 -exec env file="{}" sh -c \ 'cp -p "${file}" "${file}.ecompress.break" ; mv -f "${file}.ecompress.break" "${file}"' \; + multijob_finish + : $(( ret |= $? )) + # now lets do our work if [[ -n ${suffix} ]] ; then vecho "${0##*/}: $(ecompress --bin) /${actual_dir#${ED}}" |