Skip to content

Improve performance of parsing big integers - #717

Open
Lysxia wants to merge 4 commits into
masterfrom
read
Open

Lysxia wants to merge 4 commits into
masterfrom
read

Conversation

@Lysxia

@Lysxia Lysxia commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

After messing with the printing of integers in #716, I noticed that the parsing is naive and quadratic. This implements a quasi-linear algorithm by using the same divide-and-conquer technique as for printing.

For the lazy version, I make use of splitAtWord, so I moved it and export it from an internal module. While I was at it, I removed the awkward import of a custom strict pair, instead directly ensuring that the result doesn't produce thunks.

Added some very basic benchmarks for comparison with read/readHex on strings, mainly as a sanity check, but we can observe that we are quite faster even with a lazy text made of single-character chunks.

All
  ReadBigNumber
    Decimal
      StrictText: OK
        12.5 μs ± 1.0 μs
      LazyText:   OK
        47.2 μs ± 909 ns
      String:     OK
        64.7 μs ± 5.4 μs
    Hex
      StrictText: OK
        14.0 μs ± 256 ns
      LazyText:   OK
        49.7 μs ± 2.9 μs
      String:     OK
        80.7 μs ± 4.3 μs

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