* [gentoo-dev] [PATCH] go-module.eclass: inline _go-module_gomod_encode()
@ 2023-06-12 11:22 Florian Schmaus
2023-06-12 14:12 ` Sam James
2023-06-12 20:32 ` William Hubbs
0 siblings, 2 replies; 4+ messages in thread
From: Florian Schmaus @ 2023-06-12 11:22 UTC (permalink / raw
To: gentoo-dev; +Cc: Florian Schmaus
The only call site of _go-module_gomod_encode() was using $() in a loop
over EGO_SUM. This caused bash to fork() for every loop iteration, which
significantly affected the time it takes to "source" an ebuild using
EGO_SUM.
For example, "pkg pkg source =sys-cluster/k3s-1.23.3_p1" previously took
2.4 seconds. Inlining _go-module_gomod_encode() reduces this to
236 milliseconds.
This also adds missing 'local' declarations for some variables.
Signed-off-by: Florian Schmaus <flow@gentoo.org>
---
eclass/go-module.eclass | 44 +++++++++++++++--------------------------
1 file changed, 16 insertions(+), 28 deletions(-)
diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass
index f97b69f591c8..6c58d7f26f07 100644
--- a/eclass/go-module.eclass
+++ b/eclass/go-module.eclass
@@ -262,7 +262,22 @@ go-module_set_globals() {
continue
fi
- _dir=$(_go-module_gomod_encode "${module}")
+ # Encode the name(path) of a Golang module in the format expected by Goproxy.
+ # Upper letters are replaced by their lowercase version with a '!' prefix.
+ # The transformed result of 'module' is stored in the '_dir' variable.
+ #
+ ## Python:
+ # return re.sub('([A-Z]{1})', r'!\1', s).lower()
+ ## Sed:
+ ## This uses GNU Sed extension \l to downcase the match
+ # echo "${module}" |sed 's,[A-Z],!\l&,g'
+ local re _dir lower
+ _dir="${module}"
+ re='(.*)([A-Z])(.*)'
+ while [[ ${_dir} =~ ${re} ]]; do
+ lower='!'"${BASH_REMATCH[2],}"
+ _dir="${BASH_REMATCH[1]}${lower}${BASH_REMATCH[3]}"
+ done
for _ext in "${exts[@]}" ; do
# Relative URI within a GOPROXY for a file
@@ -496,33 +511,6 @@ go-module_live_vendor() {
popd >& /dev/null || die
}
-# @FUNCTION: _go-module_gomod_encode
-# @DEPRECATED: none
-# @DESCRIPTION:
-# Encode the name(path) of a Golang module in the format expected by Goproxy.
-#
-# Upper letters are replaced by their lowercase version with a '!' prefix.
-#
-_go-module_gomod_encode() {
- ## Python:
- # return re.sub('([A-Z]{1})', r'!\1', s).lower()
-
- ## Sed:
- ## This uses GNU Sed extension \l to downcase the match
- #echo "${module}" |sed 's,[A-Z],!\l&,g'
- #
- # Bash variant:
- debug-print-function "${FUNCNAME}" "$@"
- #local re input lower
- re='(.*)([A-Z])(.*)'
- input="${1}"
- while [[ ${input} =~ ${re} ]]; do
- lower='!'"${BASH_REMATCH[2],}"
- input="${BASH_REMATCH[1]}${lower}${BASH_REMATCH[3]}"
- done
- echo "${input}"
-}
-
fi
if [[ ! ${GO_OPTIONAL} ]]; then
--
2.39.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [gentoo-dev] [PATCH] go-module.eclass: inline _go-module_gomod_encode()
2023-06-12 11:22 [gentoo-dev] [PATCH] go-module.eclass: inline _go-module_gomod_encode() Florian Schmaus
@ 2023-06-12 14:12 ` Sam James
2023-06-12 19:34 ` Florian Schmaus
2023-06-12 20:32 ` William Hubbs
1 sibling, 1 reply; 4+ messages in thread
From: Sam James @ 2023-06-12 14:12 UTC (permalink / raw
To: gentoo-dev; +Cc: Florian Schmaus, William Hubbs
[-- Attachment #1: Type: text/plain, Size: 2853 bytes --]
Florian Schmaus <flow@gentoo.org> writes:
> The only call site of _go-module_gomod_encode() was using $() in a loop
> over EGO_SUM. This caused bash to fork() for every loop iteration, which
> significantly affected the time it takes to "source" an ebuild using
> EGO_SUM.
>
> For example, "pkg pkg source =sys-cluster/k3s-1.23.3_p1" previously took
> 2.4 seconds. Inlining _go-module_gomod_encode() reduces this to
> 236 milliseconds.
>
> This also adds missing 'local' declarations for some variables.
Nice one & lgtm, thanks!
But please remember to CC eclass maintainers (done now). If you did and
I missed it, apologies.
>
> Signed-off-by: Florian Schmaus <flow@gentoo.org>
> ---
> eclass/go-module.eclass | 44 +++++++++++++++--------------------------
> 1 file changed, 16 insertions(+), 28 deletions(-)
>
> diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass
> index f97b69f591c8..6c58d7f26f07 100644
> --- a/eclass/go-module.eclass
> +++ b/eclass/go-module.eclass
> @@ -262,7 +262,22 @@ go-module_set_globals() {
> continue
> fi
>
> - _dir=$(_go-module_gomod_encode "${module}")
> + # Encode the name(path) of a Golang module in the format expected by Goproxy.
> + # Upper letters are replaced by their lowercase version with a '!' prefix.
> + # The transformed result of 'module' is stored in the '_dir' variable.
> + #
> + ## Python:
> + # return re.sub('([A-Z]{1})', r'!\1', s).lower()
> + ## Sed:
> + ## This uses GNU Sed extension \l to downcase the match
> + # echo "${module}" |sed 's,[A-Z],!\l&,g'
> + local re _dir lower
> + _dir="${module}"
> + re='(.*)([A-Z])(.*)'
> + while [[ ${_dir} =~ ${re} ]]; do
> + lower='!'"${BASH_REMATCH[2],}"
> + _dir="${BASH_REMATCH[1]}${lower}${BASH_REMATCH[3]}"
> + done
>
> for _ext in "${exts[@]}" ; do
> # Relative URI within a GOPROXY for a file
> @@ -496,33 +511,6 @@ go-module_live_vendor() {
> popd >& /dev/null || die
> }
>
> -# @FUNCTION: _go-module_gomod_encode
> -# @DEPRECATED: none
> -# @DESCRIPTION:
> -# Encode the name(path) of a Golang module in the format expected by Goproxy.
> -#
> -# Upper letters are replaced by their lowercase version with a '!' prefix.
> -#
> -_go-module_gomod_encode() {
> - ## Python:
> - # return re.sub('([A-Z]{1})', r'!\1', s).lower()
> -
> - ## Sed:
> - ## This uses GNU Sed extension \l to downcase the match
> - #echo "${module}" |sed 's,[A-Z],!\l&,g'
> - #
> - # Bash variant:
> - debug-print-function "${FUNCNAME}" "$@"
> - #local re input lower
> - re='(.*)([A-Z])(.*)'
> - input="${1}"
> - while [[ ${input} =~ ${re} ]]; do
> - lower='!'"${BASH_REMATCH[2],}"
> - input="${BASH_REMATCH[1]}${lower}${BASH_REMATCH[3]}"
> - done
> - echo "${input}"
> -}
> -
> fi
>
> if [[ ! ${GO_OPTIONAL} ]]; then
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 377 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [gentoo-dev] [PATCH] go-module.eclass: inline _go-module_gomod_encode()
2023-06-12 14:12 ` Sam James
@ 2023-06-12 19:34 ` Florian Schmaus
0 siblings, 0 replies; 4+ messages in thread
From: Florian Schmaus @ 2023-06-12 19:34 UTC (permalink / raw
To: Sam James, gentoo-dev; +Cc: William Hubbs
[-- Attachment #1.1.1: Type: text/plain, Size: 1048 bytes --]
On 12/06/2023 16.12, Sam James wrote:
>
> Florian Schmaus <flow@gentoo.org> writes:
>
>> The only call site of _go-module_gomod_encode() was using $() in a loop
>> over EGO_SUM. This caused bash to fork() for every loop iteration, which
>> significantly affected the time it takes to "source" an ebuild using
>> EGO_SUM.
>>
>> For example, "pkg pkg source =sys-cluster/k3s-1.23.3_p1" previously took
>> 2.4 seconds. Inlining _go-module_gomod_encode() reduces this to
>> 236 milliseconds.
>>
>> This also adds missing 'local' declarations for some variables.
>
> Nice one & lgtm, thanks!
Thanks. :)
Hopefully it gets applied soon.
> But please remember to CC eclass maintainers (done now). If you did and
> I missed it, apologies.
Right, I resend the mail with only williamw in 'to' right after I send
the first mail after I noticed that I did not include the eclass
maintainer. And then I wondered if a get_maintainer script would be a
nice thing for ::gentoo. But that's a different discussion :)
- Flow
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 17273 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 618 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [gentoo-dev] [PATCH] go-module.eclass: inline _go-module_gomod_encode()
2023-06-12 11:22 [gentoo-dev] [PATCH] go-module.eclass: inline _go-module_gomod_encode() Florian Schmaus
2023-06-12 14:12 ` Sam James
@ 2023-06-12 20:32 ` William Hubbs
1 sibling, 0 replies; 4+ messages in thread
From: William Hubbs @ 2023-06-12 20:32 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 2811 bytes --]
This is applied.
Thanks,
William
On Mon, Jun 12, 2023 at 01:22:57PM +0200, Florian Schmaus wrote:
> The only call site of _go-module_gomod_encode() was using $() in a loop
> over EGO_SUM. This caused bash to fork() for every loop iteration, which
> significantly affected the time it takes to "source" an ebuild using
> EGO_SUM.
>
> For example, "pkg pkg source =sys-cluster/k3s-1.23.3_p1" previously took
> 2.4 seconds. Inlining _go-module_gomod_encode() reduces this to
> 236 milliseconds.
>
> This also adds missing 'local' declarations for some variables.
>
> Signed-off-by: Florian Schmaus <flow@gentoo.org>
> ---
> eclass/go-module.eclass | 44 +++++++++++++++--------------------------
> 1 file changed, 16 insertions(+), 28 deletions(-)
>
> diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass
> index f97b69f591c8..6c58d7f26f07 100644
> --- a/eclass/go-module.eclass
> +++ b/eclass/go-module.eclass
> @@ -262,7 +262,22 @@ go-module_set_globals() {
> continue
> fi
>
> - _dir=$(_go-module_gomod_encode "${module}")
> + # Encode the name(path) of a Golang module in the format expected by Goproxy.
> + # Upper letters are replaced by their lowercase version with a '!' prefix.
> + # The transformed result of 'module' is stored in the '_dir' variable.
> + #
> + ## Python:
> + # return re.sub('([A-Z]{1})', r'!\1', s).lower()
> + ## Sed:
> + ## This uses GNU Sed extension \l to downcase the match
> + # echo "${module}" |sed 's,[A-Z],!\l&,g'
> + local re _dir lower
> + _dir="${module}"
> + re='(.*)([A-Z])(.*)'
> + while [[ ${_dir} =~ ${re} ]]; do
> + lower='!'"${BASH_REMATCH[2],}"
> + _dir="${BASH_REMATCH[1]}${lower}${BASH_REMATCH[3]}"
> + done
>
> for _ext in "${exts[@]}" ; do
> # Relative URI within a GOPROXY for a file
> @@ -496,33 +511,6 @@ go-module_live_vendor() {
> popd >& /dev/null || die
> }
>
> -# @FUNCTION: _go-module_gomod_encode
> -# @DEPRECATED: none
> -# @DESCRIPTION:
> -# Encode the name(path) of a Golang module in the format expected by Goproxy.
> -#
> -# Upper letters are replaced by their lowercase version with a '!' prefix.
> -#
> -_go-module_gomod_encode() {
> - ## Python:
> - # return re.sub('([A-Z]{1})', r'!\1', s).lower()
> -
> - ## Sed:
> - ## This uses GNU Sed extension \l to downcase the match
> - #echo "${module}" |sed 's,[A-Z],!\l&,g'
> - #
> - # Bash variant:
> - debug-print-function "${FUNCNAME}" "$@"
> - #local re input lower
> - re='(.*)([A-Z])(.*)'
> - input="${1}"
> - while [[ ${input} =~ ${re} ]]; do
> - lower='!'"${BASH_REMATCH[2],}"
> - input="${BASH_REMATCH[1]}${lower}${BASH_REMATCH[3]}"
> - done
> - echo "${input}"
> -}
> -
> fi
>
> if [[ ! ${GO_OPTIONAL} ]]; then
> --
> 2.39.3
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-12 20:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-12 11:22 [gentoo-dev] [PATCH] go-module.eclass: inline _go-module_gomod_encode() Florian Schmaus
2023-06-12 14:12 ` Sam James
2023-06-12 19:34 ` Florian Schmaus
2023-06-12 20:32 ` William Hubbs
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox