From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 09 10:43:13 2021 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> Subject: Re: bug#50456: Optimise bytevector->nix-base32-string and bytevector->base16-string. From: Maxime Devos To: Ludovic =?ISO-8859-1?Q?Court=E8s?= 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-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 50456 Cc: 50456@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-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--