public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Florian Schmaus <flow@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: rust@gentoo.org, Florian Schmaus <flow@gentoo.org>
Subject: [gentoo-dev] [PATCH] cargo.eclass: use CARGO_CRATE_URIS if already available
Date: Mon, 31 Jul 2023 12:41:19 +0200	[thread overview]
Message-ID: <20230731104120.275384-1-flow@gentoo.org> (raw)

With 59dbfb80f748 ("cargo.eclass: Add variable alternative to
$(cargo_crate_uris)") the _cargo_set_crate_uris function was
introduced. This function runs when the elcass is inherited and sets
CARGO_CRATE_URIS.

Ebuilds that use $(cargo_crate_uris) in SRC_URI will again invoke this
function, even though CARGO_CRATE_URIS is already set. Avoiding this
unnecessary computation reduces the ebuild source time of
app-shells/nushell-0.83.0 from 21 ms to 14 ms.

This is a significant reduction when compared to the variable-setting
alternative that the commit 59dbfb80f748 ("cargo.eclass: Add variable
alternative to $(cargo_crate_uris)") introduced. Using the
variable-setting approach would reduce the ebuild source time only by a
little bit more than one millisecond.

Using

pk pkg source --bench 10s '=app-shells/nushell-0.83.0'

as benchmark, yields

|                           | Cached CARGO_CRATE_URIS | Non-Cached CARGO_CRATE_URIS |
|---------------------------+-------------------------+-----------------------------|
| $(cargo_crate_uris)       | mean: 14.189ms          | mean: 21.445ms              |
| variable-setting approach | mean: 12.822ms          | mean: 12.852ms              |

full benchmark output

|                           | Cached CARGO_CRATE_URIS (this commit)                            | Non-Cached CARGO_CRATE_URIS                                      |
|---------------------------+------------------------------------------------------------------+------------------------------------------------------------------|
| $(cargo_crate_uris)       | mean: 14.189ms, min: 13.646ms, max: 15.103ms, σ = 149µs, N = 705 | mean: 21.445ms, min: 20.79ms,  max: 22.832ms, σ = 228µs, N = 467 |
| variable-setting approach | mean: 12.822ms, min: 12.41ms,  max: 13.909ms, σ = 165µs, N = 780 | mean: 12.852ms, min: 12.367ms, max: 15.437ms, σ = 227µs, N = 779 |

Signed-off-by: Florian Schmaus <flow@gentoo.org>
---
 eclass/cargo.eclass | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index 70b6008d9cd8..5d6911801097 100644
--- a/eclass/cargo.eclass
+++ b/eclass/cargo.eclass
@@ -240,6 +240,14 @@ _cargo_set_crate_uris "${CRATES}"
 # Constructs a list of crates from its arguments.
 # If no arguments are provided, it uses the CRATES variable.
 cargo_crate_uris() {
+	# Use already existing value for CARGO_CRATE_URIS, computed by
+	# _cargo_set_crate_uris, when this function is invoked without
+	# arguments.
+	if [[ $# -eq 0 && -n "${CARGO_CRATE_URIS}" ]]; then
+		echo "${CARGO_CRATE_URIS}"
+		return
+	fi
+
 	local crates=${*-${CRATES}}
 	if [[ -z ${crates} ]]; then
 		eerror "CRATES variable is not defined and nothing passed as argument"
-- 
2.41.0



             reply	other threads:[~2023-07-31 10:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-31 10:41 Florian Schmaus [this message]
2023-07-31 11:41 ` [gentoo-dev] [PATCH] cargo.eclass: use CARGO_CRATE_URIS if already available Sam James
2023-07-31 11:42 ` Michał Górny
2023-07-31 12:44   ` Sam James
2023-07-31 12:30 ` Ionen Wolkens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230731104120.275384-1-flow@gentoo.org \
    --to=flow@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    --cc=rust@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox