Skip to content

Extend performance group with Text/ByteString strictness hints#1693

Open
mgajda wants to merge 1 commit intondmitchell:masterfrom
mgajda:performance-text-bs
Open

Extend performance group with Text/ByteString strictness hints#1693
mgajda wants to merge 1 commit intondmitchell:masterfrom
mgajda:performance-text-bs

Conversation

@mgajda
Copy link
Copy Markdown

@mgajda mgajda commented Apr 20, 2026

Part of a set of independent PRs adding rules to the opt-in
performance group (disabled by default; enabled via
--with-group=performance or per-project config). Each PR in the set
targets a separate rule family and can be reviewed/merged
independently.

This one covers Data.Text / Data.ByteString strict-variant rewrites.

Rules added

All matches use fully-qualified module names so they fire only on the
exact lazy imports users wrote (never on Prelude/Foldable foldl).

  • Data.Text.foldl / Data.Text.Lazy.foldl -> foldl'
  • Data.ByteString.foldl / Data.ByteString.Lazy.foldl -> foldl'
  • Data.ByteString.Char8.foldl / Data.ByteString.Lazy.Char8.foldl -> foldl'
  • Data.Text.concat (map f xs) -> Data.Text.concatMap f xs
  • Data.Text.Lazy.concat (map f xs) -> Data.Text.Lazy.concatMap f xs

Data.ByteString.concatMap has a different type
((Word8 -> ByteString) -> ByteString -> ByteString) so the
concat . map fusion rule is deliberately NOT applied there.

Adds same-module, semantics-preserving strict-variant rewrites for
Data.Text / Data.ByteString and their Lazy and Char8 variants in the
opt-in performance group. All patterns use fully-qualified module names
so they only fire on the exact import users actually wrote.

- Data.Text.foldl / Data.Text.Lazy.foldl -> foldl' (strict left fold)
- Data.ByteString.foldl / Data.ByteString.Lazy.foldl -> foldl'
- Data.ByteString.Char8.foldl / Data.ByteString.Lazy.Char8.foldl -> foldl'
- Data.Text.concat (map f xs) -> Data.Text.concatMap f xs
- Data.Text.Lazy.concat (map f xs) -> Data.Text.Lazy.concatMap f xs

Not included: Data.ByteString.concat . map fusion. Data.ByteString's
concatMap has signature (Word8 -> ByteString) -> ByteString -> ByteString,
so it is NOT the fusion of concat . map over [ByteString].

Nor are any lazy-type-to-strict-type rewrites (e.g. Data.Text.Lazy.pack
-> Data.Text.pack) included; those change semantics and would silently
break code that needs lazy I/O.
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