From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id KGzYFS8eOmEKfwAAgWs5BA (envelope-from ) for ; Thu, 09 Sep 2021 16:46:07 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id gDmAES8eOmE5TAAA1q6Kng (envelope-from ) for ; Thu, 09 Sep 2021 14:46:07 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D8A4D14B29 for ; Thu, 9 Sep 2021 16:46:05 +0200 (CEST) Received: from localhost ([::1]:51988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOLJU-0001o4-Ps for larch@yhetil.org; Thu, 09 Sep 2021 10:46:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34584) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOLHW-0008Fo-Oe for guix-patches@gnu.org; Thu, 09 Sep 2021 10:44:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:52618) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mOLHW-00036K-CQ for guix-patches@gnu.org; Thu, 09 Sep 2021 10:44:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mOLHW-0000AI-AO for guix-patches@gnu.org; Thu, 09 Sep 2021 10:44:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50456] Optimise bytevector->nix-base32-string and bytevector->base16-string. Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 09 Sep 2021 14:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50456 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 50456@debbugs.gnu.org Received: via spool by 50456-submit@debbugs.gnu.org id=B50456.1631198593557 (code B ref 50456); Thu, 09 Sep 2021 14:44:02 +0000 Received: (at 50456) by debbugs.gnu.org; 9 Sep 2021 14:43:13 +0000 Received: from localhost ([127.0.0.1]:35925 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mOLGi-00008t-WF for submit@debbugs.gnu.org; Thu, 09 Sep 2021 10:43:13 -0400 Received: from baptiste.telenet-ops.be ([195.130.132.51]:60508) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mOLGf-00008b-M0 for 50456@debbugs.gnu.org; Thu, 09 Sep 2021 10:43:11 -0400 Received: from butterfly.local ([188.189.231.0]) by baptiste.telenet-ops.be with bizsmtp id rqj32500M01AJj801qj66e; Thu, 09 Sep 2021 16:43:07 +0200 Message-ID: <86e6e4cf87fce8ed4b970568b9c9b375d03a5505.camel@telenet.be> From: Maxime Devos Date: Thu, 09 Sep 2021 16:42:58 +0200 In-Reply-To: <87o891esah.fsf@gnu.org> References: <7831fcdd8b8aab99cc95ba904076014b4c3cb6d2.camel@telenet.be> <87o891esah.fsf@gnu.org> Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-ZIYlsB89j0FaSXMI5UI7" User-Agent: Evolution 3.34.2 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1631198587; bh=J3rf9yqikQ0S0CgoVgSsXuZ4EpzHeazfMG0b+mDaDKA=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=POpJvSjgmfd5k1K4AGzLEYowFVFVjIOrFMmyEOoWzV6d1TVQEJkJfTaTuaLkvgLRc 1lJP7uyMUkb4t5mBnqz4MvK9z9zjRvuKOWTY5KCh3x2uFi7TtERhaIlWX+WskMAMph hydg54eX9eJG2u84ZvQdEbj5oDHqCedL5vwIp8nOv7r6wVBbuX5ggBUXDmfMddABt+ K+dQLZOq3SZOp5AyR7piS4FDrEBF9VoH71+iTA96l8YGc5keIF8fCag7N1amQZON8p T8v59tnzuSj9LKmlXJkf1ULRJYY/9T8AlCpXD/Ep6FXhJJvFb2UqFvYyxhI3e4hC5t 6H7nxTyWfkZzA== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1631198767; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=J3rf9yqikQ0S0CgoVgSsXuZ4EpzHeazfMG0b+mDaDKA=; b=Hgm6IAWbYM4GGvhQejqDKkKTtXGYdaeKOFSAWhSl1FZcQtSr1tAkOg0bFWOmAdIUXb9VuW LN2RdJglAvooRpzp9z8s3fBXbhzdtdLPZmhRdjoX8E6QKVIAxMxTJLOYNbD4hhPKeAVntY o12boMA1EG33/ucSNtz5+YxD5Wx9Vip8KcOFQ/fi4oSgyfnkbgMZk5mBRMTepWhmLZZ/lw iGWmjkXAz1Da7C4uLVARpaMV6G8bGBRuTQ4Z+qoQlP1IgHgABjq6Ryh+6ewmlDI6K7bvhk RXRlKla0qF2wiTFqby//kkI+fogHGwaMSzOjsDE1R2iPtKdSjgkLdJzxX9RHcg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1631198767; a=rsa-sha256; cv=none; b=tT9clhMn6iepEOYGCXlmmvr13Wcs9kyt1M3eJjFNKbUY/ezM29QLaUeYTc9sguoOmrX1xO rrxr/cSXxZQqiUMXqra38Wz6nAmF/5M5P5D1XXpCvxtY/RQQwlZrN/K5mi9w+sSOeY/SvT CoW/RzHWFmmxpKZ0rzGv4IORMuyrJJOcou4io1QBzz6pyfc4DpD30H4X1wWUwQ5cclCXzS tg7pbS/Zj4EesmMyLsTlkQJWQTY8DDnPRW9FpLXT6gSefeEDL5vx69nF9cw+pX6FkJ1Fyw wxI90Ds3fvus/ThU/auXUrJZcQwuNP/VIOKQsLPAJXwEK5xCeKh0kQxe//bBpA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r21 header.b=POpJvSjg; dmarc=fail reason="SPF not aligned (relaxed)" header.from=telenet.be (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -3.41 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r21 header.b=POpJvSjg; dmarc=fail reason="SPF not aligned (relaxed)" header.from=telenet.be (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: D8A4D14B29 X-Spam-Score: -3.41 X-Migadu-Scanner: scn0.migadu.com X-TUID: HrAcNsJN3Tmh --=-ZIYlsB89j0FaSXMI5UI7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s schreef op do 09-09-2021 om 16:29 [+0200]: > Hello, >=20 > Maxime Devos skribis: >=20 > > The two atached patches optimise bytevector->nix-base32-string and > > bytevector->base16-string, making them about 20% and two times > > faster respectively, by reducing allocations. They are called > > from 'output-path', 'fixed-output-path' and 'store-path' > > in (guix store). >=20 > Thanks a lot for looking into this! >=20 > > Unfortunately, this does not decrease timings to a noticable degree, > > but it does decrease the allocated memory by 2.3% (*), and it does not > > seem to increase timings. (See perf-numbers.txt.) >=20 > Yeah, base32 code is usually pretty low in profiles of calls to > =E2=80=98package-derivation=E2=80=99. >=20 > > From a93bad629e2746c77446cacddb9986506ce9ba88 Mon Sep 17 00:00:00 2001 > > From: Maxime Devos > > Date: Sun, 5 Sep 2021 16:28:33 +0200 > > Subject: [PATCH 1/2] base32: Reduce GC pressure in > > make-bytevector->base32-string. > >=20 > > The following code has been used to compare performance: > >=20 > > ;; first 20 bytes of sha256 of #vu8(#xde #xad #xbe #xef) > > (define bv #vu8(95 120 195 50 116 228 63 169 222 86 89 38 92 29 145 126= 37 192 55 34)) > > ,profile > > (let loop ((n 0)) > > (when (< n #e1e6) > > ((@ (guix base32) bytevector->nix-base32-string) bv) > > (loop (+ n 1)))) > >=20 > > Before this change, the output was: > >=20 > > [...] > > Sample count: 1140 > > Total time: 27.465560018 seconds (10.659331433 seconds in GC) > >=20 > > After this change, the output was: > >=20 > > [...] > > Sample count: 957 > > Total time: 20.478847143 seconds (6.139721189 seconds in GC) >=20 > Note that ,profile (statprof) is intrusive; additional, the REPL uses > the =E2=80=9Cdebug=E2=80=9D VM engine, which is slightly slower than the = =E2=80=9Cregular=E2=80=9D one > (info "(guile) Command-line Options"). >=20 > To measure =E2=80=9Cactual=E2=80=9D performance, it=E2=80=99s best to wri= te the code down in a > file and then run: >=20 > time guile -l that-file.scm >=20 > or, alternatively, use (ice-9 time) and wrap the body of the relevant > code in (time =E2=80=A6), which is a bit more accurate than using the she= ll=E2=80=99s > =E2=80=98time=E2=80=99 command since it allows you to dismiss Guile start= up time. I'll test with ((@ (ice-9 time) ...). > (You also need to make sure that the loop counter remains below > =E2=80=98most-positive-fixnum=E2=80=99, otherwise you=E2=80=99ll end up m= easuring GC activity > due to the use of bignums, but 10=E2=81=B6 is definitely OK.) >=20 > > * guix/base32.scm > > (make-bytevector->base32-string): Eliminate 'reverse', use mutation i= nstead. >=20 > [...] >=20 > > + (let* ((start (cons #f #f)) > > + (end (quintet-fold (lambda (q r) > > + (define pair > > + (cons (vector-ref base32-chars q) #f= )) > > + (set-cdr! r pair) > > + pair) > > + start > > + bv))) > > + (set-cdr! end '()) > > + (list->string (cdr start))))) >=20 > Does replacing (reverse chars) with (reverse! chars) has the same > effect? Not tested. > I=E2=80=99m reluctant to resorting to micro-optimizations like the one ab= ove > since they make code harder to reason about. Agreed, let's drop that patch. > > From dfd9b7557e31823320fcbd7abed77de295b7dce1 Mon Sep 17 00:00:00 2001 > > From: Maxime Devos > > Date: Mon, 6 Sep 2021 00:46:17 +0200 > > Subject: [PATCH 2/2] base16: Reduce GC pressure in bytevector->base16-s= tring. > >=20 > > This makes bytevector->base16-string two times faster. > >=20 > > * guix/base16.scm (bytevector->base16-string): Use utf8->string > > and iteration instead of string-concatenate and named let. >=20 > LGTM. How did you measure performance for this one? IIRC, the same way as with bytevector->base32-string. I'll retest with (ice-9 time). Greetings, Maxime. --=-ZIYlsB89j0FaSXMI5UI7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYTodchccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7o92APwMMvSu7NAFOEyDafcW4OahGsB6 k6jLS72HTMIjltUcyQD+NF7xLsJkjzrrgltwr65QCzRW+3iEJt/LVIlavV+QFgw= =wiOW -----END PGP SIGNATURE----- --=-ZIYlsB89j0FaSXMI5UI7--