diff options
author | Bartosz Nitka <niteria@gmail.com> | 2017-01-23 09:51:31 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-01-23 14:17:34 -0500 |
commit | 532c6ade49e9e8e7e98c35451058ba7e4ee7bb9c (patch) | |
tree | de85c211d2da57538875cc615522fc118045aba5 | |
parent | 596dece7866006d699969f775fd97bd306aad85b (diff) | |
download | haskell-532c6ade49e9e8e7e98c35451058ba7e4ee7bb9c.tar.gz |
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
-rw-r--r-- | compiler/basicTypes/SrcLoc.hs | 13 | ||||
-rw-r--r-- | 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 45d92d0188..af757f5ca7 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 bcf9e6eb4d..4ea913bfa1 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 |