text icon indicating copy to clipboard operation
text copied to clipboard

`fromString` from `Data.Text.Lazy.Builder` generates massive amount of code

Open TheKK opened this issue 7 months ago • 3 comments

The code sample looks like

{-# LANGUAGE OverloadedStrings #-}

f :: B.Builder
f = "a cat" <> "a dog" <> "a fish"

By using Builder from bytestring, the above code generates about 30 lines of core (compiler explorer), but we got 2200 lines when switching to text (compiler explorer)

This becomes a problem since I use katip for logging and it uses Builder from text internally. It's very common to use string literal to construct Builder while logging.

Possible root cause and solution

fromString has INLINE

This is the most obvious reason why it produce so many code. They are inlined three times and it seems that there's nothing (eg. RULE) to make them shorter.

But it's hard for me to tell if removing INLINE would make performance worse or not. (And I see no benchmark involve fromString)

Related issue

#19 (it's issue of pre 2.0 text which still use RULE to fuse though)

TheKK avatar Dec 06 '23 15:12 TheKK