text
text copied to clipboard
`fromString` from `Data.Text.Lazy.Builder` generates massive amount of code
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)
Yeah, I suspect that {-# INLINE fromString #-}
is a bad idea: it should be {-# INLINABLE fromString #-}
at most. PR is welcome.
Should I check anything or write some new benchmarks first?
Checking that the change actually improves Core code bloat would be great.