Skip to content
  • Tobias Dammers's avatar
    Caching coercion roles in NthCo and coercionKindsRole refactoring · 2fbe0b51
    Tobias Dammers authored and Ben Gamari's avatar Ben Gamari committed
    While addressing nonlinear behavior related to coercion roles,
    particularly `NthCo`, we noticed that coercion roles are recalculated
    often even though they should be readily at hand already in most cases.
    This patch adds a `Role` to the `NthCo` constructor so that we can cache
    them rather than having to recalculate them on the fly.
    https://ghc.haskell.org/trac/ghc/ticket/11735#comment:23 explains the
    approach.
    
    Performance improvement over GHC HEAD, when compiling Grammar.hs (see below):
    
    GHC 8.2.1:
    ```
    ghc Grammar.hs  176.27s user 0.23s system 99% cpu 2:56.81 total
    ```
    
    before patch (but with other optimizations applied):
    ```
    ghc Grammar.hs -fforce-recomp  175.77s user 0.19s system 100% cpu 2:55.78 total
    ```
    
    after:
    ```
    ../../ghc/inplace/bin/ghc-stage2 Grammar.hs  10.32s user 0.17s system 98% cpu 10.678 total
    ```
    
    Introduces the following regressions:
    
    - perf/compiler/parsing001 (possibly false positive)
    - perf/compiler/T9872
    - perf/compiler/haddock.base
    
    Reviewers: goldfire, bgamari, simonpj
    
    Reviewed By: simonpj
    
    Subscribers: rwbarton, thomie, carter
    
    GHC Trac Issues: #11735
    
    Differential Revision: https://phabricator.haskell.org/D4394
    2fbe0b51