From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-dev+bounces-100206-garchives=archives.gentoo.org@lists.gentoo.org>
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 71EAA15800A
	for <garchives@archives.gentoo.org>; Mon, 31 Jul 2023 11:42:26 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id A0896E0CB8;
	Mon, 31 Jul 2023 11:42:23 +0000 (UTC)
Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183])
	(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 611C8E0CB1
	for <gentoo-dev@lists.gentoo.org>; Mon, 31 Jul 2023 11:42:23 +0000 (UTC)
Message-ID: <c44f55f4e50a64580f44a8c1d0b73e8cd91de028.camel@gentoo.org>
Subject: Re: [gentoo-dev] [PATCH] cargo.eclass: use CARGO_CRATE_URIS if
 already available
From: =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?= <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: rust@gentoo.org, Florian Schmaus <flow@gentoo.org>
Date: Mon, 31 Jul 2023 13:42:18 +0200
In-Reply-To: <20230731104120.275384-1-flow@gentoo.org>
References: <20230731104120.275384-1-flow@gentoo.org>
Organization: Gentoo
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
User-Agent: Evolution 3.48.4 
Precedence: bulk
List-Post: <mailto:gentoo-dev@lists.gentoo.org>
List-Help: <mailto:gentoo-dev+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-dev+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-dev+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-dev.gentoo.org>
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
X-Archives-Salt: b0f103cd-cbc7-4560-8877-26626502c230
X-Archives-Hash: c50a9aa8d341b957625f57b1fa262bf7

On Mon, 2023-07-31 at 12:41 +0200, Florian Schmaus wrote:
> 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.
>=20
> 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.
>=20
> 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.
>=20
> Using
>=20
> pk pkg source --bench 10s '=3Dapp-shells/nushell-0.83.0'
>=20
> as benchmark, yields
>=20
> >                           | 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   =
           |
>=20
> full benchmark output
>=20
> >                           | Cached CARGO_CRATE_URIS (this commit)      =
                      | Non-Cached CARGO_CRATE_URIS                        =
              |
> > ---------------------------+-------------------------------------------=
-----------------------+---------------------------------------------------=
---------------|
> > $(cargo_crate_uris)       | mean: 14.189ms, min: 13.646ms, max: 15.103m=
s, =CF=83 =3D 149=C2=B5s, N =3D 705 | mean: 21.445ms, min: 20.79ms,  max: 2=
2.832ms, =CF=83 =3D 228=C2=B5s, N =3D 467 |
> > variable-setting approach | mean: 12.822ms, min: 12.41ms,  max: 13.909m=
s, =CF=83 =3D 165=C2=B5s, N =3D 780 | mean: 12.852ms, min: 12.367ms, max: 1=
5.437ms, =CF=83 =3D 227=C2=B5s, N =3D 779 |
>=20
> Signed-off-by: Florian Schmaus <flow@gentoo.org>
> ---
>  eclass/cargo.eclass | 8 ++++++++
>  1 file changed, 8 insertions(+)
>=20
> 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=3D${*-${CRATES}}
>  	if [[ -z ${crates} ]]; then
>  		eerror "CRATES variable is not defined and nothing passed as argument"

This incorrectly assumes that the value of CRATES did not change which
isn't guaranteed anywhere.

--=20
Best regards,
Micha=C5=82 G=C3=B3rny