From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 2FAC2158008 for ; Thu, 15 Jun 2023 15:53:52 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C391CE09D0; Thu, 15 Jun 2023 15:52:55 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 86263E09CD for ; Thu, 15 Jun 2023 15:52:55 +0000 (UTC) From: Sam James To: gentoo-dev@lists.gentoo.org Cc: ruby@gentoo.org, Sam James Subject: [gentoo-dev] [PATCH 04/11] ruby-ng.eclass: optimize: avoid subshells for _ruby_atoms_samelib* Date: Thu, 15 Jun 2023 16:52:31 +0100 Message-ID: <20230615155240.589982-4-sam@gentoo.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230615155240.589982-1-sam@gentoo.org> References: <20230615155240.589982-1-sam@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archives-Salt: bf06dc65-c8c7-40d8-9d96-299d2e95d7df X-Archives-Hash: 182b1bb1c282a4fe10910ccec80b2150 - Inline ruby_atoms_samelib (only used by one caller) - Avoid repeated (subshell) calls to _ruby_atoms_samelib_generic by using a result variable instead. We go from 3.5s -> 2.5s to source dev-ruby/*. Thanks to mgorny for the ideas here. Bug: https://bugs.gentoo.org/908465 Signed-off-by: Sam James --- eclass/ruby-ng.eclass | 57 ++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass index ee2e6b89edb41..cf66fcec2f05d 100644 --- a/eclass/ruby-ng.eclass +++ b/eclass/ruby-ng.eclass @@ -141,23 +141,6 @@ ruby_samelib() { echo "[${res%,}]" } -_ruby_atoms_samelib_generic() { - eshopts_push -o noglob - echo "RUBYTARGET? (" - for token in $*; do - case "$token" in - "||" | "(" | ")" | *"?") - echo "${token}" ;; - *]) - echo "${token%[*}[RUBYTARGET(-),${token/*[}" ;; - *) - echo "${token}[RUBYTARGET(-)]" ;; - esac - done - echo ")" - eshopts_pop -} - # @FUNCTION: ruby_implementation_command # @RETURN: the path to the given ruby implementation # @DESCRIPTION: @@ -173,11 +156,29 @@ ruby_implementation_command() { echo $(type -p ${_ruby_name} 2>/dev/null) } +_RUBY_ATOMS_SAMELIB_RESULT="" _ruby_atoms_samelib() { - local atoms=$(_ruby_atoms_samelib_generic "$*") + _RUBY_ATOMS_SAMELIB_RESULT="" + + eshopts_push -o noglob + local token + local atoms=" RUBYTARGET? (" + for token in $*; do + case "${token}" in + "||" | "(" | ")" | *"?") + atoms+=" ${token}" ;; + *]) + atoms+=" ${token%[*}[RUBYTARGET(-),${token/*[}" ;; + *) + atoms+=" ${token}[RUBYTARGET(-)]" ;; + esac + done + atoms+=" ) " + eshopts_pop + local _ruby_implementation for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do - echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}" + _RUBY_ATOMS_SAMELIB_RESULT+="${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}" done } @@ -226,15 +227,15 @@ ruby_add_rdepend() { ;; esac - local dependency=$(_ruby_atoms_samelib "$1") + _ruby_atoms_samelib "$1" - RDEPEND="${RDEPEND} $dependency" + RDEPEND="${RDEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}" # Add the dependency as a test-dependency since we're going to # execute the code during test phase. case ${EAPI} in - 6) DEPEND="${DEPEND} test? ( ${dependency} )" ;; - *) BDEPEND="${BDEPEND} test? ( ${dependency} )" ;; + 6) DEPEND="${DEPEND} test? ( ${_RUBY_ATOMS_SAMELIB_RESULT} )" ;; + *) BDEPEND="${BDEPEND} test? ( ${_RUBY_ATOMS_SAMELIB_RESULT} )" ;; esac if ! has test "$IUSE"; then IUSE+=" test" @@ -273,11 +274,11 @@ ruby_add_bdepend() { ;; esac - local dependency=$(_ruby_atoms_samelib "$1") + _ruby_atoms_samelib "$1" case ${EAPI} in - 6) DEPEND="${DEPEND} $dependency" ;; - *) BDEPEND="${BDEPEND} $dependency" ;; + 6) DEPEND="${DEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}" ;; + *) BDEPEND="${BDEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}" ;; esac RDEPEND="${RDEPEND}" } @@ -300,9 +301,9 @@ ruby_add_depend() { *) die "bad number of arguments to $0" ;; esac - local dependency=$(_ruby_atoms_samelib "$1") + _ruby_atoms_samelib "$1" - DEPEND="${DEPEND} $dependency" + DEPEND="${DEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}" } # @FUNCTION: ruby_get_use_implementations -- 2.41.0