[commit: ghc] master: Make tickishContains faster (532c6ad)

git at git.haskell.org git at git.haskell.org
Mon Jan 23 19:17:54 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/532c6ade49e9e8e7e98c35451058ba7e4ee7bb9c/ghc

>---------------------------------------------------------------

commit 532c6ade49e9e8e7e98c35451058ba7e4ee7bb9c
Author: Bartosz Nitka <niteria at gmail.com>
Date:   Mon Jan 23 09:51:31 2017 -0500

    Make tickishContains faster
    
    This just reorders some inequality checks to make the common case
    cheaper.
    
    The results are quite dramatic for #11095, but that's probably because
    something else is causing it to do too much work.
    
    Before (full https://phabricator.haskell.org/P136):
    ```
      13,589,495,832 bytes allocated in the heap
    ```
    
    After (full https://phabricator.haskell.org/P137):
    ```
       7,885,575,872 bytes allocated in the heap
    ```
    
    This is with `BuildFlavour = devel2`, so take it with a
    a grain of salt.
    
    For reference, with no `-g` I get:
    ```
    155,703,112 bytes allocated in the heap
    ```
    so we're still quite a way off.
    
    Test Plan:
    harbormaster
    I still have to test locally
    
    Reviewers: austin, bgamari
    
    Subscribers: thomie, simonmar
    
    Differential Revision: https://phabricator.haskell.org/D3001
    
    GHC Trac Issues: #11095


>---------------------------------------------------------------

532c6ade49e9e8e7e98c35451058ba7e4ee7bb9c
 compiler/basicTypes/SrcLoc.hs | 13 ++++++++-----
 compiler/coreSyn/CoreSyn.hs   |  3 ++-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/compiler/basicTypes/SrcLoc.hs b/compiler/basicTypes/SrcLoc.hs
index 45d92d0..af757f5 100644
--- a/compiler/basicTypes/SrcLoc.hs
+++ b/compiler/basicTypes/SrcLoc.hs
@@ -344,11 +344,14 @@ isOneLineSpan (UnhelpfulSpan _) = False
 -- that it covers at least as much source code. True where spans are equal.
 containsSpan :: RealSrcSpan -> RealSrcSpan -> Bool
 containsSpan s1 s2
-  = srcSpanFile s1 == srcSpanFile s2
-    && (srcSpanStartLine s1, srcSpanStartCol s1)
-       <= (srcSpanStartLine s2, srcSpanStartCol s2)
-    && (srcSpanEndLine s1, srcSpanEndCol s1)
-       >= (srcSpanEndLine s2, srcSpanEndCol s2)
+  =  srcSpanEndCol s1 >= srcSpanEndCol s2
+  && srcSpanStartCol s1 <= srcSpanStartCol s2
+  && srcSpanEndLine s1 >= srcSpanEndLine s2
+  && srcSpanStartLine s1 <= srcSpanStartLine s2
+  && srcSpanFile s1 == srcSpanFile s2
+  -- ordered roughly by the likelihood of failing:
+  --   * we're more likely to be comparing source spans from the same file
+  --   * we're more likely to be comparing source spans on the same line
 
 {-
 %************************************************************************
diff --git a/compiler/coreSyn/CoreSyn.hs b/compiler/coreSyn/CoreSyn.hs
index bcf9e6e..4ea913b 100644
--- a/compiler/coreSyn/CoreSyn.hs
+++ b/compiler/coreSyn/CoreSyn.hs
@@ -809,7 +809,8 @@ tickishPlace SourceNote{}  = PlaceNonLam
 -- making the second tick redundant.
 tickishContains :: Eq b => Tickish b -> Tickish b -> Bool
 tickishContains (SourceNote sp1 n1) (SourceNote sp2 n2)
-  = n1 == n2 && containsSpan sp1 sp2
+  = containsSpan sp1 sp2 && n1 == n2
+    -- compare the String last
 tickishContains t1 t2
   = t1 == t2
 



More information about the ghc-commits mailing list