Skip to content

Improve performance of parsing big integers - #717

Merged
Lysxia merged 4 commits into
masterfrom
read
Nov 13, 2026
Merged

Lysxia merged 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

Comment thread src/Data/Text/Read.hs Resolved
@Lysxia
Lysxia force-pushed the read branch 2 times, most recently from 4ba3244 to 8828e17 Compare November 13, 2026 00:39
@Lysxia
Lysxia merged commit 2962b87 into master Nov 13, 2026
48 checks passed
@Lysxia
Lysxia deleted the read branch November 13, 2026 09:27
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.

2 participants