Gentoo Archives: gentoo-portage-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH] prepman: do not compress files <=128 bytes
Date: Wed, 20 Mar 2013 08:33:27
Message-Id: 1363768625-9717-1-git-send-email-vapier@gentoo.org
1 The vast majority of these small files do not compress better than
2 their inputs, and they're just .so redirection. Omit compression
3 on them to save disk and cpu and speed things up.
4
5 URL: http://bugs.gentoo.org/169260
6 Signed-off-by: Mike Frysinger <vapier@g.o>
7 ---
8 bin/ebuild-helpers/ecompressdir | 33 ++++++++++++++++++++++++++-------
9 bin/ebuild-helpers/prepman | 5 ++++-
10 2 files changed, 30 insertions(+), 8 deletions(-)
11
12 diff --git a/bin/ebuild-helpers/ecompressdir b/bin/ebuild-helpers/ecompressdir
13 index 75f3e3a..bde2cca 100755
14 --- a/bin/ebuild-helpers/ecompressdir
15 +++ b/bin/ebuild-helpers/ecompressdir
16 @@ -13,7 +13,9 @@ if ! ___eapi_has_prefix_variables; then
17 ED=${D} EPREFIX=
18 fi
19
20 -case $1 in
21 +SIZE_LIMIT=''
22 +while [[ $# -gt 0 ]] ; do
23 + case $1 in
24 --ignore)
25 shift
26 for skip in "$@" ; do
27 @@ -28,7 +30,8 @@ case $1 in
28 set -- "${@/#/${ED}}"
29 ret=0
30 for x in "$@" ; do
31 - >> "$x"
32 + # Stash the limit in the .dir file so we can reload it later.
33 + printf ${SIZE_LIMIT} > "${x}"
34 ((ret|=$?))
35 done
36 [[ $ret -ne 0 ]] && __helpers_die "${0##*/} failed"
37 @@ -42,29 +45,44 @@ case $1 in
38 find "${ED}" -name '*.ecompress.skip' -print0 | ${XARGS} -0 rm -f
39 exit 0
40 ;;
41 + --limit)
42 + SIZE_LIMIT=$2
43 + shift
44 + ;;
45 --*)
46 __helpers_die "${0##*/}: unknown arguments '$*'"
47 exit 1
48 ;;
49 -esac
50 + *)
51 + break
52 + ;;
53 + esac
54 + shift
55 +done
56
57 # figure out the new suffix
58 suffix=$(ecompress --suffix)
59
60 -# funk_up_dir(action, suffix, binary)
61 +# funk_up_dir(action, suffix, binary, [size_limit])
62 # - action: compress or decompress
63 # - suffix: the compression suffix to work with
64 # - binary: the program to execute that'll compress/decompress
65 +# - size_limit: if compressing, skip files smaller than this
66 # The directory we act on is implied in the ${dir} variable
67 funk_up_dir() {
68 - local act=$1 suffix=$2 binary=$3
69 + local act=$1 suffix=$2 binary=$3 size_limit=$4
70
71 local negate=""
72 [[ ${act} == "compress" ]] && negate="!"
73
74 local ret=0
75 # first we act on all the files
76 - find "${dir}" -type f ${negate} -iname '*'${suffix} -print0 | ${XARGS} -0 ${binary}
77 + local args=(
78 + -type f
79 + ${negate} -iname "*${suffix}"
80 + )
81 + [[ -n ${size_limit} ]] && args+=( -size "+${size_limit}c" )
82 + find "${dir}" "${args[@]}" -print0 | ${XARGS} -0 ${binary}
83 ((ret|=$?))
84
85 while read -r -d $'\0' brokenlink ; do
86 @@ -152,6 +170,7 @@ for dir in "$@" ; do
87
88 # since we've been requested to compress the whole dir,
89 # delete any individual queued requests
90 + size_limit=${SIZE_LIMIT:-$(<"${actual_dir}.ecompress.dir")}
91 rm -f "${actual_dir}.ecompress.dir"
92 find "${dir}" -type f -name '*.ecompress.file' -print0 | ${XARGS} -0 rm -f
93
94 @@ -179,7 +198,7 @@ for dir in "$@" ; do
95 # now lets do our work
96 if [[ -n ${suffix} ]] ; then
97 __vecho "${0##*/}: $(ecompress --bin) /${actual_dir#${ED}}"
98 - funk_up_dir "compress" "${suffix}" "ecompress"
99 + funk_up_dir "compress" "${suffix}" "ecompress" "${size_limit}"
100 : $(( ret |= $? ))
101 fi
102
103 diff --git a/bin/ebuild-helpers/prepman b/bin/ebuild-helpers/prepman
104 index 55a9483..fb5dcb4 100755
105 --- a/bin/ebuild-helpers/prepman
106 +++ b/bin/ebuild-helpers/prepman
107 @@ -2,6 +2,9 @@
108 # Copyright 1999-2012 Gentoo Foundation
109 # Distributed under the terms of the GNU General Public License v2
110
111 +# Do not compress man pages which are smaller than this (in bytes). #169260
112 +SIZE_LIMIT='128'
113 +
114 source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh
115
116 if ! ___eapi_has_prefix_variables; then
117 @@ -31,6 +34,6 @@ for subdir in "${mandir}"/man* "${mandir}"/*/man* ; do
118 [[ -d ${subdir} ]] && really_is_mandir=1 && break
119 done
120
121 -[[ ${really_is_mandir} == 1 ]] && exec ecompressdir --queue "${mandir#${ED}}"
122 +[[ ${really_is_mandir} == 1 ]] && exec ecompressdir --limit ${SIZE_LIMIT} --queue "${mandir#${ED}}"
123
124 exit 0
125 --
126 1.8.1.2

Replies