Changes between Initial Version and Version 1 of Ticket #11284


Ignore:
Timestamp:
Dec 24, 2015 4:33:03 PM (4 years ago)
Author:
bgamari
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #11284

    • Property Type of failure changed from None/Unknown to Runtime performance bug
  • Ticket #11284 – Description

    initial v1  
    1 Consider the example,
     1Consider the example (which uses `Text`; I'm working on finding a more minimal example),
    22{{{#!hs
    33import Data.Char (isSpace)
     
    1818}}}
    1919
     20`longestWord` here produces the simplified Core`,
     21
     22{{{#!hs
     23Rec {
     24Ticket.$wgo1 :: [T.Text] -> GHC.Prim.Int# -> GHC.Prim.Int#
     25Ticket.$wgo1 =
     26  \ (w_s4GJ :: [T.Text]) (ww_s4GN :: GHC.Prim.Int#) ->
     27    case w_s4GJ of _ {
     28      [] -> ww_s4GN;
     29      : y_a4vC ys_a4vD ->
     30        case y_a4vC
     31        of _ { Data.Text.Internal.Text dt_a4jP dt1_a4jQ dt2_a4jR ->
     32        let {
     33          a_a4jO :: GHC.Prim.Int#
     34          a_a4jO = GHC.Prim.+# dt1_a4jQ dt2_a4jR } in
     35        letrec {
     36          -- Why must you allocate? For the love of all that is good, why?
     37          $wloop_length_s4GI :: GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.Int#
     38          $wloop_length_s4GI =
     39            \ (ww1_s4Gz :: GHC.Prim.Int#) (ww2_s4GD :: GHC.Prim.Int#) ->
     40              case GHC.Prim.tagToEnum# @ Bool (GHC.Prim.>=# ww2_s4GD a_a4jO) -- bounds check
     41              of _ {
     42                False -> {
     43                  ...
     44                  -- in this body there are few cases analyses with
     45                  -- recursive calls of the form
     46                  $wloop_length_s4GI (GHC.Prim.+# ww1_s4Gz 1) (GHC.Prim.+# ww2_s4GD 1)
     47                  ...
     48                True -> ww1_s4Gz
     49              }; } in
     50        case $wloop_length_s4GI 0 dt1_a4jQ of ww1_s4GH { __DEFAULT ->
     51        case GHC.Prim.tagToEnum# @ Bool (GHC.Prim.<=# ww_s4GN ww1_s4GH)
     52        of _ {
     53          False -> Ticket.$wgo1 ys_a4vD ww_s4GN;
     54          True -> Ticket.$wgo1 ys_a4vD ww1_s4GH
     55        }
     56        }
     57        }
     58    }
     59end Rec }
     60
     61longestWord :: T.Text -> Int
     62longestWord =
     63  \ (w_s4GT :: T.Text) ->
     64    case w_s4GT
     65    of _ { Data.Text.Internal.Text ww1_s4GW ww2_s4GX ww3_s4GY ->
     66    case Ticket.$wgo1 (Ticket.$wgo ww1_s4GW ww2_s4GX ww3_s4GY) 0
     67    of ww4_s4H2 { __DEFAULT ->
     68    GHC.Types.I# ww4_s4H2
     69    }
     70    }
     71}}}
     72
     73Notice `$wloop_length_s4GI`: It should be a nice tight loop traversing `dt_a4jP :: ByteArray#` until it finds whitespace. However, GHC fails to lambda-lift this closure, thereby turning it into an allocating operation! Oh no!