Skip to content

Commit 44fdcbc

Browse files
committed
NOINLINE string8 and stringUtf8
If they inline too early, our RULEs may be ineffective. Better performance was observed with `INLINE [0]` than `INLINE [1]`, but `NOINLINE` works at least as well.
1 parent 052affb commit 44fdcbc

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Data/ByteString/Builder.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ char8 :: Char -> Builder
442442
char8 = P.primFixed P.char8
443443

444444
-- | Char8 encode a 'String'.
445-
{-# INLINE [1] string8 #-} -- phased to allow literal cstring rewrites
445+
{-# NOINLINE string8 #-}
446446
string8 :: String -> Builder
447447
string8 = P.primMapListFixed P.char8
448448

@@ -471,7 +471,7 @@ charUtf8 = P.primBounded P.charUtf8
471471
--
472472
-- Note that 'stringUtf8' performs no codepoint validation and consequently may
473473
-- emit invalid UTF-8 if asked (e.g. single surrogates).
474-
{-# INLINE [1] stringUtf8 #-} -- phased to allow literal cstring rewrites
474+
{-# NOINLINE stringUtf8 #-}
475475
stringUtf8 :: String -> Builder
476476
stringUtf8 = P.primMapListBounded P.charUtf8
477477

bench/BenchAll.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ asclit, utflit :: Ptr Word8 -> Builder
259259
asclit str@(Ptr addr) = BI.ascLiteralCopy str (byteCountLiteral addr)
260260
utflit str@(Ptr addr) = BI.modUtf8LitCopy str (byteCountLiteral addr)
261261

262+
ascStr, utfStr :: String
263+
ascStr = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
264+
utfStr = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
265+
262266
main :: IO ()
263267
main = do
264268
defaultMain
@@ -273,6 +277,10 @@ main = do
273277
, benchB' "String" () $ \() -> asclit (Ptr "hello world!"#)
274278
, benchB' "AsciiLit" () $ \() -> asclit ascBuf
275279
, benchB' "Utf8Lit" () $ \() -> utflit utfBuf
280+
, benchB' "strLit" () $ \() -> string8 ascStr
281+
, benchB' "utfLit" () $ \() -> stringUtf8 utfStr
282+
, benchB' "strLitInline" () $ \() -> string8 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
283+
, benchB' "utfLitInline" () $ \() -> stringUtf8 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
276284
]
277285

278286
, bgroup "Encoding wrappers"

0 commit comments

Comments
 (0)