Skip to content
Snippets Groups Projects
  1. Jul 26, 2023
    • Bodigrim's avatar
      Let the list instance fuse · 406b6cf1
      Bodigrim authored
      To measure performance of `someFunc` Haskell benchmarks often employ code like this:
      
      ```haskell
      map someFunc [1..1000] `deepseq` ()
      ```
      
      Here we want to measure time of 1000 applications of `someFunc`, and in order to do so we `deepseq` the entire list `map someFunc [1..1000]`. However, in this scenario we are not really interested in materializing the list: if `someFunc` is relatively fast, allocations are likely to skew measurements. See https://github.com/Bodigrim/tasty-bench/issues/48#issuecomment-1606049088 for discussion and various hacky workarounds.
      
      We can do better by making `instance NFData [a]` able to fuse by rewriting it via `foldr`. This has a nice side effect of avoiding manual recursion and having a more concise definition as well.
      
      Before the patch
      
      ```haskell
      foo :: Int -> ()
      foo n = [1..n] `deepseq` ()
      ```
      
      compiles to
      
      ```haskell
      Rec {
      $wgo3 :: [Int] -> (# #)
      $wgo3
        = \ (ds_s8hJ :: [Int]) ->
            case ds_s8hJ of {
              [] -> (##);
              : y_i8gZ ys_i8h0 -> case y_i8gZ of { I# ipv_i8gR -> $wgo3 ys_i8h0 }
            }
      end Rec }
      
      $wfoo :: Int# -> (# #)
      $wfoo
        = \ (ww_s8hT :: Int#) ->
            case ># 1# ww_s8hT of {
              __DEFAULT ->
                letrec {
                  go3_a8hF :: Int# -> [Int]
                  go3_a8hF
                    = \ (x_a8hG :: Int#) ->
                        : (I# x_a8hG)
                          (case ==# x_a8hG ww_s8hT of {
                             __DEFAULT -> go3_a8hF (+# x_a8hG 1#);
                             1# -> []
                           }); } in
                $wgo3 (go3_a8hF 1#);
              1# -> (##)
            }
      
      foo :: Int -> ()
      foo
        = \ (n_s8hR :: Int) ->
            case n_s8hR of { I# ww_s8hT ->
            case $wfoo ww_s8hT of { (# #) -> () }
            }
      ```
      
      Here one can observe `$wgo3` which is forcing a list (essentially this is `rnf` from `instance NFData [a]`) and `go3_a8hF` which produces it. Such code allocates boxed `Int` and `(:)` constructors.
      
      After the patch:
      
      ```haskell
      foo :: Int -> ()
      foo
        = \ (n_a8g8 :: Int) ->
            case n_a8g8 of { I# y_a8ha ->
            case ># 1# y_a8ha of {
              __DEFAULT ->
                joinrec {
                  go3_a5N1 :: Int# -> ()
                  go3_a5N1 (x_a5N2 :: Int#)
                    = case ==# x_a5N2 y_a8ha of {
                        __DEFAULT -> jump go3_a5N1 (+# x_a5N2 1#);
                        1# -> ()
                      }; } in
                jump go3_a5N1 1#;
              1# -> ()
            }
            }
      ```
      
      Here we do force evaluation of all elements of the list, but do not allocate them.
      406b6cf1
  2. Jan 29, 2023
  3. Jan 28, 2023
  4. Jan 24, 2023
  5. Jan 22, 2023
  6. Aug 26, 2022
  7. Aug 18, 2022
  8. Jun 19, 2022
    • Oleg Grenrus's avatar
      Change RnfArgs to be data family · fd074a43
      Oleg Grenrus authored
      Then we don't rely that heavily on simplifier to remove the GADT
      overhead. Even when unoptimized, there isn't additional
      box over RnfArgs1.
      
      I did similar change to hashable in 2019.
      fd074a43
  9. May 04, 2022
  10. Dec 05, 2021
  11. Dec 01, 2021
  12. Nov 14, 2021
  13. Apr 14, 2021
  14. Aug 17, 2020
  15. Jul 19, 2020
  16. Jun 17, 2020
  17. Jul 17, 2019
    • Ryan Scott's avatar
      Documentation improvements for the URec instance (#48) · 78ce5abb
      Ryan Scott authored
      This fixes a handful of minor issues with the `NFData` instance for
      `URec`:
      
      * It had a `@since` annotation without Haddock formatting.
      * It did not mention that it was only available on `base-4.9` or
        later.
      * The CPP referred to `__GLASGOW_HASKELL__`, not
        `MIN_VERSION_base(4,9,0)` like it should have.
      
      This patch fixes all of these problems.
      78ce5abb
  18. Jun 24, 2019
  19. Sep 15, 2018
  20. Mar 20, 2018
  21. Mar 12, 2018
  22. Apr 22, 2017
    • Herbert Valerio Riedel's avatar
      Refactor and extend documentation · 0b22c982
      Herbert Valerio Riedel authored
      With the recent new API additions it makes sense to restructure
      a bit. Moreoever, this commit augments the new NFData1/NFData2 API
      with a few more haddock strings, and extends the introductory examples.
      0b22c982
  23. Apr 16, 2017
  24. Apr 15, 2017
  25. Apr 08, 2017
  26. Feb 27, 2017
Loading