Re: [scala-debate] Extremely slow patmat phase of compilation

181 views
Skip to first unread message

Jon Pretty

unread,
Feb 24, 2015, 4:25:54 PM2/24/15
to Rado Buranský, scala-...@googlegroups.com
It looks like exhaustivity checking: removing `sealed` from the trait allows me to compile it in 43s. As I'm typing this, the `sealed` version is still compiling after five minutes.

Here's a pretty graph of how long it took to compile different numbers of cases with the supertrait `sealed` and not.


That doesn't look linear to me. The culprit should be relatively easy to find with a profiler...

Cheers,
Jon


On Tue Feb 24 2015 at 21:50:43 Rado Buranský <radobu...@gmail.com> wrote:
Can anybody tell me why this code takes endless time  to compile? What is the compiler doing so much and how can I help it?

You can find full source code here:

sealed trait C
case object C1 extends C
case object C2 extends C
case object C3 extends C
...
case object C399 extends C
case object C400 extends C

object M {
  def f(c: C): Int = c match {
    case C1 => 1
    case C2 => 2
    case C3 => 3
    ...
    case C399 => 399
    case C400 => 400
  }
}

--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-debate+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jon Pretty

unread,
Feb 24, 2015, 5:01:33 PM2/24/15
to Rado Buranský, scala-...@googlegroups.com
I've just been notified on Twitter by a friendly observer that this doesn't happen in Scala 2.11.4, so it's a recent regression.

You can avoid this by downgrading to Scala 2.11.4 or using -Xno-patmat-analysis (which turns off exhaustivity checking).

I've filed an issue here: https://issues.scala-lang.org/browse/SI-9181

Cheers,
Jon

Jason Zaugg

unread,
Feb 24, 2015, 5:07:44 PM2/24/15
to Jon Pretty, Rado Buranský, scala-debate
On Wed, Feb 25, 2015 at 8:01 AM, Jon Pretty <prope...@gmail.com> wrote:
I've just been notified on Twitter by a friendly observer that this doesn't happen in Scala 2.11.4, so it's a recent regression.

You can avoid this by downgrading to Scala 2.11.4 or using -Xno-patmat-analysis (which turns off exhaustivity checking).

Or more locally by (scrutinee: Any) match { ... }.

Thanks, Jon.

-jason

Rado Buranský

unread,
Feb 25, 2015, 3:42:16 AM2/25/15
to scala-...@googlegroups.com, prope...@gmail.com, radobu...@gmail.com
Thanks a lot
Reply all
Reply to author
Forward
0 new messages