Re: [PATCH] basenc: improve base58 encoding performance without gmplib
From:
Collin Funk
Subject:
Re: [PATCH] basenc: improve base58 encoding performance without gmplib
Date:
Fri, 09 Oct 2026 20:20:48 -0700
User-agent:
Gnus/5.13 (Gnus v5.13)
PƔdraig Brady <P@draigBrady.com> writes:
> $ ./configure --without-libgmp --quiet
> $ dd bs=64k count=1 if=/dev/urandom of=58.in
>
> $ time src/basenc-before --base58 58.in >/dev/null
> real 0m6.588s
>
> $ time src/basenc-after --base58 58.in >/dev/null
> real 0m3.463s
>
> * src/basenc.c (base58_encode): Remove an affirm that is very expensive
> in the minigmp implementation. Essentially the same affirm was done
> at the start of the function anyway.
> ---
> src/basenc.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/src/basenc.c b/src/basenc.c
> index a9c9f2f30..8aaef0d8b 100644
> --- a/src/basenc.c
> +++ b/src/basenc.c
> @@ -1289,7 +1289,6 @@ base58_encode (char const *data, size_t data_len,
> if (data_len - zeros)
> {
> mpz_import (num, data_len - zeros, 1, 1, 0, 0, data + zeros);
> - affirm (mpz_sizeinbase (num, 58) + 1 <= *outlen);
> for (p = mpz_get_str (p, 58, num); *p; p++)
> *p = gmp_to_base58[to_uchar (*p)];
> }
Nice catch on that and the other patch to mini-gmp.
By the way, today I found out Gentoo's coreutils package uses mini-gmp
by default. It looks like Sam is looking to change that, though [1]. I
wonder if any other distributions choose to use mini-gmp for some
reason.
Collin
[1]
https://archives.gentoo.org/gentoo-dev/bf22d6afd355e01a4c1479ab2b21076f75468578.1790430550.git.sam@gentoo.org/