title: Aeson lazy parser
body: <p>The Aeson library offers two flavors of json parser: a strict one and a lazy one. The lazy one claims to save time but creat thunks, whereas the strict one saves space and takes more time (both if the data isn't accessed frequently). I have the following toy program to see the difference between them, but the profiles are identical: </p>
  
  <pre><code>import Data.Aeson
  import Data.ByteString as B
  import Data.Attoparsec.ByteString as P
  import System.Environment
  
  main = do
      [fn] &lt;- getArgs
      fc &lt;- B.readFile fn
      let r = P.parse json' fc
      case r
        of Done _ _ -&gt; print ":)"
           _   -&gt; print ":("
  </code></pre>
  
  <p>Two parsers also have identical performance when the program access the data fully: </p>
  
  <pre><code>    ...
      case r
        of Done _ j -&gt; print j
           _   -&gt; print ":("
  </code></pre>
  
  <p>Why doesn't the lazy version save time in the first program and waste space in the second? Is there an example where one of the parsers clearly wins? </p>
  
  <p>Update: Following is my recent experiment with <code>FromJSON</code>, which also failed to differentiate <code>decode</code> from <code>decode'</code></p>
  
  <pre><code>Data Weirder = Weirder
  
  instance FromJSON Weirder where
      parseJSON (Number n) = return $! undefined -- $! trace "weirdercalled" Weirder -- `seq` Weirder
  
  main = do
      [fn] &lt;- getArgs
      fc &lt;- B.readFile fn
      let Just rs = decode fc :: Maybe [Weirder]
      print $ length rs
  </code></pre>
  
  <p>I've tried printing <code>head</code>, <code>last</code>, flipping bangs and inserting <code>seq</code>, yet all the same...</p>