Skip to content

Fewer ByteString allocations in CPS parser with ByteStringIdx - #46

Merged
mzabani merged 12 commits into
inline-record-row-decodersfrom
cps-parser-fewer-bytestrings
Aug 24, 2026
Merged

Fewer ByteString allocations in CPS parser with ByteStringIdx#46
mzabani merged 12 commits into
inline-record-row-decodersfrom
cps-parser-fewer-bytestrings

Conversation

@mzabani

@mzabani mzabani commented Aug 14, 2026

Copy link
Copy Markdown
Owner

Part 2 of performance optimizations

Compared to master:

  • Tuple Stream benchmark (with lots of runs, times of each run added together) went from 38433.4 to 36612.7ms, total memory allocated from 9470MB to 8410MB. That's a 4.8% wall time reduction and a 11.2% total memory allocated reduction
  • Record stream benchmark went from 145.009s to 133.26s, total memory allocated from 10314MB to 9668MB. That's a 8.1% wall time reduction and a ~6.3% total memory allocated reduction

From the GHC Core, the main difference here is that in row decoders, parser continuations don't require allocating new ByteStrings, just Ints (ByteStringIdx). I don't expect this made a difference here, but it will be useful for future optimizations.

What this also does is push the part of the code that converts ByteString -> [a] (where a is the user's target row type) down in a way that we can avoid creating one instance of ByteString per row, and instead pass a big chunk of rows as the same single ByteString, and further down we can parseMany directly from that to [a].

@mzabani mzabani changed the title Fewer ByteString allocations in CPS parser Fewer ByteString allocations in CPS parser with ByteStringIdx Aug 15, 2026
@mzabani
mzabani force-pushed the cps-parser-fewer-bytestrings branch from e9d01e1 to 253fbd7 Compare August 23, 2026 13:29
@mzabani
mzabani marked this pull request as ready for review August 23, 2026 22:29
@mzabani
mzabani merged commit f6f8985 into master Aug 24, 2026
3 checks passed
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