Skip to content

Greatly improve BigInt decimal formatting and parsing performance - #6137

Merged
randombit merged 2 commits into
masterfrom
jack/bigint-decimal-opt
Nov 17, 2026
Merged

randombit merged 2 commits into
masterfrom
jack/bigint-decimal-opt

Conversation

@randombit

@randombit randombit commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Parsing large decimal strings (>2048 bits) is 3x faster, and reaches almost 4x faster for 4 million bits.

Decimal formatting gets a more or less uniform speedup of 3.5x-4x

The second commit, optimizing the constant time comparison mask generation, also improves other unrelated algorithms including the generic division algorithm and FrodoKEM.

Both remain quadratic, but with a much smaller constant.

Formatting is 2.5x to 3.9x faster and parsing up to 3.5x faster.

Improve tests for decimal parsing and formatting.
This improves many uses of this function, for example division of a
BigInt by a word is up to 1.4x faster, ct_divide and ct_modulo up to
1.25x, and decimal formatting of large values 1.3x. FrodoKEM, which
uses ::is_lt in its sampling loop, is 3% to 16% faster.

Checked with valgrind on x86-64 (Clang and GCC), and also checked
Clang's codegen across 17 target architectures.
@randombit
randombit merged commit df10cbc into master Nov 17, 2026
51 checks passed
@randombit
randombit deleted the jack/bigint-decimal-opt branch November 17, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant