New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pathologically slow compilation time with -optimize and named/default arguments #7524

Closed
scabug opened this Issue May 28, 2013 · 7 comments

Comments

Projects
None yet
2 participants
@scabug
Copy link

scabug commented May 28, 2013

With -optimize on, this code takes 30 seconds to compile, compared to 5 seconds without the optimizer. If you double the number of repetitions in the body of O, it takes several minutes. Something O(n^2) or worse must be happening.

Scala 2.9.2, 2.10.1, 2.10.2-RC1, and 2.11.0.M2 are all equally affected.

I encountered this bug in real code, with a large literal Map containing a lot (about 400) case class instances.

case class S(
  a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0,
  f: Int = 0, g: Int = 0, h: Int = 0, i: Int = 0, j: Int = 0)

object O {
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
  S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0); S(j = 0)
}
@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 28, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7524?orig=1
Reporter: @SethTisue
Affected Versions: 2.10.1

@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 28, 2013

@SethTisue said:
pretty much any thread dump I grab shows the compiler spending its time in this line of ReachingDefinitions.scala:

      (rd filter { case (l, _, _) => l != tmp }) + ((tmp, b, idx))

so this may date back to scala/scala@28f747a

@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 28, 2013

@paulp said:
ListSet. Enough said.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 28, 2013

@paulp said:
After replacing ListSet with LinkedHashSet:

% time scalac3 -optimise a.scala
64.175 real, 73.388 user, 0.433 sys
% time qscalac -optimise a.scala
10.709 real, 20.147 user, 0.491 sys
@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 28, 2013

@SethTisue said:
the trigger is default arguments, not named arguments; supplying all arguments makes the problem go away. so that's the workaround I'll use for now

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Jun 1, 2013

@SethTisue said:
further workaround notes: -optimize is just a combination of other flags, and for this issue it's the -Ydead-code part of it that's the culprit, so one workaround is to disable -optimize but then individually opt in to other parts of it (such as -Yinline)

@scabug scabug added this to the Backlog milestone Apr 7, 2017

@scala scala deleted a comment from scabug Mar 1, 2018

@SethTisue

This comment has been minimized.

Copy link
Member

SethTisue commented Mar 1, 2018

we can reopen if someone can reproduce this with the new optimizer in 2.12

@SethTisue SethTisue closed this Mar 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment