on master help sign in
Some tweaks for encodeUtf8 perf
eeb84b0Harendra Kumar
docs/Build.md+1−1
@@ -2,7 +2,7 @@
2
2
3Recommended GHC options are:
3Recommended GHC options are:
4
4
5− `-O2 -fspec-constr-recursive=10 -fmax-worker-args=16`
5+ `-O2 -fspec-constr-recursive=16 -fmax-worker-args=16`
6
6
7`-fspec-constr-recursive` is needed for better stream fusion by enabling
7`-fspec-constr-recursive` is needed for better stream fusion by enabling
8the `SpecConstr` optimization in more cases.
8the `SpecConstr` optimization in more cases.
src/Streamly/Streams/StreamD.hs+5−2
@@ -3815,6 +3815,10 @@ data WList = WCons !Word8 !WList | WNil
3815
3815
3816data EncodeState s = EncodeState s !WList
3816data EncodeState s = EncodeState s !WList
3817
3817
3818+-- More yield points improve performance, but I am not sure if they can cause
3819+-- too much code bloat or some trouble with fusion. So keeping only two yield
3820+-- points for now, one for the ascii chars (fast path) and one for all other
3821+-- paths (slow path).
3818{-# INLINE_NORMAL encodeUtf8 #-}
3822{-# INLINE_NORMAL encodeUtf8 #-}
3819encodeUtf8 :: Monad m => Stream m Char -> Stream m Word8
3823encodeUtf8 :: Monad m => Stream m Char -> Stream m Word8
3820encodeUtf8 (Stream step state) = Stream step' (EncodeState state WNil)
3824encodeUtf8 (Stream step state) = Stream step' (EncodeState state WNil)
@@ -3828,8 +3832,7 @@ encodeUtf8 (Stream step state) = Stream step' (EncodeState state WNil)
3828 case ord c of
3832 case ord c of
3829 x
3833 x
3830 | x <= 0x7F ->
3834 | x <= 0x7F ->
3831− Skip
3832− (EncodeState s (WCons (fromIntegral x) WNil))
3835+ Yield (fromIntegral x) (EncodeState s WNil)
3833 | x <= 0x7FF -> Skip (EncodeState s (ord2 c))
3836 | x <= 0x7FF -> Skip (EncodeState s (ord2 c))
3834 | x <= 0xFFFF ->
3837 | x <= 0xFFFF ->
3835 if isSurrogate c
3838 if isSurrogate c
streamly.cabal+1−1
@@ -205,7 +205,7 @@ common compile-options
205
205
206common optimization-options
206common optimization-options
207 ghc-options: -O2
207 ghc-options: -O2
208− -fspec-constr-recursive=10
208+ -fspec-constr-recursive=16
209 -fmax-worker-args=16
209 -fmax-worker-args=16
210
210
211common threading-options
211common threading-options