Commit 532c6ade authored by niteria's avatar niteria Committed by Ben Gamari
Browse files

Make tickishContains faster

This just reorders some inequality checks to make the common case

The results are quite dramatic for #11095, but that's probably because
something else is causing it to do too much work.

Before (full
  13,589,495,832 bytes allocated in the heap

After (full
   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:
I still have to test locally

Reviewers: austin, bgamari

Subscribers: thomie, simonmar

Differential Revision:

GHC Trac Issues: #11095
parent 596dece7
......@@ -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
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment