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 AA328158008 for ; Thu, 15 Jun 2023 15:53:32 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id AB11EE09C2; Thu, 15 Jun 2023 15:52:54 +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) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 6BED1E09BF for ; Thu, 15 Jun 2023 15:52:54 +0000 (UTC) From: Sam James To: gentoo-dev@lists.gentoo.org Cc: ruby@gentoo.org, Sam James Subject: [gentoo-dev] [PATCH 03/11] ruby-ng.eclass: optimize: avoid subshell for ruby_get_all_impls Date: Thu, 15 Jun 2023 16:52:30 +0100 Message-ID: <20230615155240.589982-3-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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: 4456157f-ae8e-4ca5-9d56-ce9b1a9dbb3a X-Archives-Hash: 1e02b2cca932d559f952a0f99c2cee42 We go from ~4s -> ~3.5s for sourcing dev-ruby/*. For sinatra: ``` $ pk pkg source $(pkg) --repo ~/g/ --bench 5s # before dev-ruby/sinatra-2.2.3::/home/sam/g/: mean: 66.68ms, min: 56.938ms, max: 74.248ms, σ = 4.832ms, N = 75 dev-ruby/sinatra-3.0.6::/home/sam/g/: mean: 73.618ms, min: 60.153ms, max: 77.978ms, σ = 3.195ms, N = 68 dev-ruby/sinatra-3.0.5::/home/sam/g/: mean: 72.069ms, min: 58.736ms, max: 78.223ms, σ = 3.277ms, N = 70 dev-ruby/sinatra-3.0.5-r1::/home/sam/g/: mean: 73.265ms, min: 60.738ms, max: 81.06ms, σ = 3.227ms, N = 69 $ pk pkg source $(pkg) --repo ~/g/ --bench 5s # after dev-ruby/sinatra-3.0.5-r1::/home/sam/g/: mean: 59.677ms, min: 49.141ms, max: 63.282ms, σ = 2.511ms, N = 84 dev-ruby/sinatra-3.0.6::/home/sam/g/: mean: 59.693ms, min: 48.637ms, max: 62.862ms, σ = 2.628ms, N = 84 dev-ruby/sinatra-3.0.5::/home/sam/g/: mean: 56.697ms, min: 46.782ms, max: 60.367ms, σ = 2.822ms, N = 89 dev-ruby/sinatra-2.2.3::/home/sam/g/: mean: 54.915ms, min: 45.832ms, max: 59.513ms, σ = 3.52ms, N = 92 ``` Bug: https://bugs.gentoo.org/908465 Signed-off-by: Sam James --- eclass/ruby-ng.eclass | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass index 2bf1885d38031..ee2e6b89edb41 100644 --- a/eclass/ruby-ng.eclass +++ b/eclass/ruby-ng.eclass @@ -102,6 +102,7 @@ ruby_implementation_depend() { # @DESCRIPTION: # Return a list of valid implementations in USE_RUBY, skipping the old # implementations that are no longer supported. +_RUBY_GET_ALL_IMPLS=() _ruby_get_all_impls() { local i found_valid_impl for i in ${USE_RUBY}; do @@ -111,7 +112,8 @@ _ruby_get_all_impls() { ;; *) found_valid_impl=1 - echo ${i};; + _RUBY_GET_ALL_IMPLS+=( ${i} ) + ;; esac done @@ -131,7 +133,7 @@ ruby_samelib() { debug-print-function ${FUNCNAME} "${@}" local res= - for _ruby_implementation in $(_ruby_get_all_impls); do + for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do has -${_ruby_implementation} $@ || \ res="${res}ruby_targets_${_ruby_implementation}(-)?," done @@ -174,7 +176,7 @@ ruby_implementation_command() { _ruby_atoms_samelib() { local atoms=$(_ruby_atoms_samelib_generic "$*") - for _ruby_implementation in $(_ruby_get_all_impls); do + for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}" done } @@ -310,7 +312,7 @@ ruby_get_use_implementations() { debug-print-function ${FUNCNAME} "${@}" local i implementation - for implementation in $(_ruby_get_all_impls); do + for implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do use ruby_targets_${implementation} && i+=" ${implementation}" done echo $i @@ -322,8 +324,8 @@ ruby_get_use_implementations() { ruby_get_use_targets() { debug-print-function ${FUNCNAME} "${@}" - - local impls="$(_ruby_get_all_impls)" + _ruby_get_all_impls + local impls="${_RUBY_GET_ALL_IMPLS[@]}" echo "${impls//ruby/ruby_targets_ruby}" } @@ -346,13 +348,14 @@ ruby_get_use_targets() { ruby_implementations_depend() { debug-print-function ${FUNCNAME} "${@}" - local depend - for _ruby_implementation in $(_ruby_get_all_impls); do + for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do depend="${depend}${depend+ }ruby_targets_${_ruby_implementation}? ( $(ruby_implementation_depend $_ruby_implementation) )" done echo "${depend}" } +_ruby_get_all_impls + IUSE+=" $(ruby_get_use_targets)" # If you specify RUBY_OPTIONAL you also need to take care of # ruby useflag and dependency. @@ -412,7 +415,7 @@ _ruby_invoke_environment() { _ruby_each_implementation() { local invoked=no - for _ruby_implementation in $(_ruby_get_all_impls); do + for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do # only proceed if it's requested use ruby_targets_${_ruby_implementation} || continue @@ -435,7 +438,7 @@ _ruby_each_implementation() { if [[ ${invoked} == "no" ]]; then eerror "You need to select at least one compatible Ruby installation target via RUBY_TARGETS in make.conf." - eerror "Compatible targets for this package are: $(_ruby_get_all_impls)" + eerror "Compatible targets for this package are: ${_RUBY_GET_ALL_IMPLS[@]}" eerror eerror "See https://www.gentoo.org/proj/en/prog_lang/ruby/index.xml#doc_chap3 for more information." eerror -- 2.41.0