git.iko.soy/typeable/attoparsec
on master help sign in
Fix exponential compilation times due to inlining

Always inlining the success continuation helps performance but explodes the code size so that compiling even small examples such as calling anyWord8 16 times in a row slows to a crawl. Fixes #38

commiteb5cefd0e4c18e8a9a2567e32dcd8a998d36c60f authorJohan Tibell <johan.tibell@gmail.com> dateFri 30 Nov 2012, 15:19 (14 years ago) parentb17af7f
2 files changed+2−15
Data/Attoparsec/ByteString/Internal.hs+1−7 Data/Attoparsec/Text/Internal.hs+1−8
Data/Attoparsec/ByteString/Internal.hs+1−7
@@ -85,13 +85,9 @@ import qualified Data.ByteString.Unsafe as B
8585
8686#if defined(__GLASGOW_HASKELL__)
8787import GHC.Base (realWorld#)
88−import GHC.Exts (inline)
8988import GHC.IO (IO(IO))
9089#else
9190import System.IO.Unsafe (unsafePerformIO)
92−
93−inline :: a -> a
94−inline x = x
9591#endif
9692
9793type Parser = T.Parser B.ByteString
@@ -116,9 +112,7 @@ ensure' !n0 i0 a0 m0 kf0 ks0 =
116112ensure :: Int -> Parser B.ByteString
117113ensure !n = T.Parser $ \i0 a0 m0 kf ks ->
118114 if B.length (unI i0) >= n
119− -- Inline the success continuation to avoid creating a closure in
120− -- the common case of enough data in the buffer:
121− then inline ks i0 a0 m0 (unI i0)
115+ then ks i0 a0 m0 (unI i0)
122116 -- The uncommon case is kept out-of-line to reduce code size:
123117 else ensure' n i0 a0 m0 kf ks
124118-- Non-recursive so the bounds check can be inlined:
Data/Attoparsec/Text/Internal.hs+1−8
@@ -78,13 +78,6 @@ import qualified Data.Text as T
7878import qualified Data.Text.Internal as T
7979import qualified Data.Text.Lazy as L
8080
81−#if defined(__GLASGOW_HASKELL__)
82−import GHC.Exts (inline)
83−#else
84−inline :: a -> a
85−inline x = x
86−#endif
87−
8881type Parser = T.Parser Text
8982type Result = IResult Text
9083type Input = T.Input Text
@@ -104,7 +97,7 @@ lengthAtLeast t@(T.Text _ _ len) n = (len `div` 2) >= n || T.length t >= n
10497ensure :: Int -> Parser Text
10598ensure !n = T.Parser $ \i0 a0 m0 kf ks ->
10699 if lengthAtLeast (unI i0) n
107− then inline ks i0 a0 m0 (unI i0)
100+ then ks i0 a0 m0 (unI i0)
108101 else runParser (demandInput >> go n) i0 a0 m0 kf ks
109102 where
110103 go n' = T.Parser $ \i0 a0 m0 kf ks ->