[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gentoo-portage-dev
Subject:    [gentoo-portage-dev] [PATCH] prepman: do not compress files <=128 bytes
From:       Mike Frysinger <vapier () gentoo ! org>
Date:       2013-03-20 8:37:05
Message-ID: 1363768625-9717-1-git-send-email-vapier () gentoo ! org
[Download RAW message or body]

The vast majority of these small files do not compress better than
their inputs, and they're just .so redirection.  Omit compression
on them to save disk and cpu and speed things up.

URL: http://bugs.gentoo.org/169260
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 bin/ebuild-helpers/ecompressdir | 33 ++++++++++++++++++++++++++-------
 bin/ebuild-helpers/prepman      |  5 ++++-
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/bin/ebuild-helpers/ecompressdir b/bin/ebuild-helpers/ecompressdir
index 75f3e3a..bde2cca 100755
--- a/bin/ebuild-helpers/ecompressdir
+++ b/bin/ebuild-helpers/ecompressdir
@@ -13,7 +13,9 @@ if ! ___eapi_has_prefix_variables; then
 	ED=${D} EPREFIX=
 fi
 
-case $1 in
+SIZE_LIMIT=''
+while [[ $# -gt 0 ]] ; do
+	case $1 in
 	--ignore)
 		shift
 		for skip in "$@" ; do
@@ -28,7 +30,8 @@ case $1 in
 		set -- "${@/#/${ED}}"
 		ret=0
 		for x in "$@" ; do
-			>> "$x"
+			# Stash the limit in the .dir file so we can reload it later.
+			printf ${SIZE_LIMIT} > "${x}"
 			((ret|=$?))
 		done
 		[[ $ret -ne 0 ]] && __helpers_die "${0##*/} failed"
@@ -42,29 +45,44 @@ case $1 in
 		find "${ED}" -name '*.ecompress.skip' -print0 | ${XARGS} -0 rm -f
 		exit 0
 		;;
+	--limit)
+		SIZE_LIMIT=$2
+		shift
+		;;
 	--*)
 		__helpers_die "${0##*/}: unknown arguments '$*'"
 		exit 1
 		;;
-esac
+	*)
+		break
+		;;
+	esac
+	shift
+done
 
 # figure out the new suffix
 suffix=$(ecompress --suffix)
 
-# funk_up_dir(action, suffix, binary)
+# funk_up_dir(action, suffix, binary, [size_limit])
 #	- action: compress or decompress
 #	- suffix: the compression suffix to work with
 #	- binary: the program to execute that'll compress/decompress
+#   - size_limit: if compressing, skip files smaller than this
 # The directory we act on is implied in the ${dir} variable
 funk_up_dir() {
-	local act=$1 suffix=$2 binary=$3
+	local act=$1 suffix=$2 binary=$3 size_limit=$4
 
 	local negate=""
 	[[ ${act} == "compress" ]] && negate="!"
 
 	local ret=0
 	# first we act on all the files
-	find "${dir}" -type f ${negate} -iname '*'${suffix} -print0 | ${XARGS} -0 ${binary}
+	local args=(
+		-type f
+		${negate} -iname "*${suffix}"
+	)
+	[[ -n ${size_limit} ]] && args+=( -size "+${size_limit}c" )
+	find "${dir}" "${args[@]}" -print0 | ${XARGS} -0 ${binary}
 	((ret|=$?))
 
 	while read -r -d $'\0' brokenlink ; do
@@ -152,6 +170,7 @@ for dir in "$@" ; do
 
 	# since we've been requested to compress the whole dir,
 	# delete any individual queued requests
+	size_limit=${SIZE_LIMIT:-$(<"${actual_dir}.ecompress.dir")}
 	rm -f "${actual_dir}.ecompress.dir"
 	find "${dir}" -type f -name '*.ecompress.file' -print0 | ${XARGS} -0 rm -f
 
@@ -179,7 +198,7 @@ for dir in "$@" ; do
 	# now lets do our work
 	if [[ -n ${suffix} ]] ; then
 		__vecho "${0##*/}: $(ecompress --bin) /${actual_dir#${ED}}"
-		funk_up_dir "compress" "${suffix}" "ecompress"
+		funk_up_dir "compress" "${suffix}" "ecompress" "${size_limit}"
 		: $(( ret |= $? ))
 	fi
 
diff --git a/bin/ebuild-helpers/prepman b/bin/ebuild-helpers/prepman
index 55a9483..fb5dcb4 100755
--- a/bin/ebuild-helpers/prepman
+++ b/bin/ebuild-helpers/prepman
@@ -2,6 +2,9 @@
 # Copyright 1999-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+# Do not compress man pages which are smaller than this (in bytes). #169260
+SIZE_LIMIT='128'
+
 source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh
 
 if ! ___eapi_has_prefix_variables; then
@@ -31,6 +34,6 @@ for subdir in "${mandir}"/man* "${mandir}"/*/man* ; do
 	[[ -d ${subdir} ]] && really_is_mandir=1 && break
 done
 
-[[ ${really_is_mandir} == 1 ]] && exec ecompressdir --queue "${mandir#${ED}}"
+[[ ${really_is_mandir} == 1 ]] && exec ecompressdir --limit ${SIZE_LIMIT} --queue "${mandir#${ED}}"
 
 exit 0
-- 
1.8.1.2



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic