Skip to content
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

Intersection is too slow for case class with more than 6 fields #793

Closed
sergei-grigorev opened this issue Dec 8, 2017 · 5 comments
Closed

Comments

@sergei-grigorev
Copy link

So, shapeless.ops.hlist.Intersection takes too much time to compile. In my case it's impossible to wait for a case class with 10 fields. But for a test only - 6 and 7 fields also takes too much time.

    test("too slow to compile") {
      case class C1(f1: String, f2: String, f3: String, f4: String, f5: String, f6: String, f7: String)
      case class C2(f1: String, f2: String, f3: String, f4: String, f5: String, f6: String, f7: String)

      val gen = LabelledGeneric[C1]
      val gen2 = LabelledGeneric[C2]
      val inter = hlist.Intersection[gen.Repr, gen2.Repr]
    }

In my case of course classes is a little different, it's just a test case. Is there any compiler optimization to pass this problem?

@milessabin
Copy link
Owner

Have you tried TLS with -Yinduction-heuristics?

@sergei-grigorev
Copy link
Author

@milessabin have tried but the situation almost isn't changed, it still takes ages. For example, 37 seconds for 7 fields and 108 seconds for 8 fields. I haven't got result for 9 fields

@joroKr21
Copy link
Collaborator

@sergeygrigorev a lot of fields is not enough to make it slow. Your example above compiles in a few seconds. I think the worst case would be to have a lot of fields of different types in reverse order. Like so:

case class C1(f1: Byte, f2: Short, f3: Char, f4: Int, f5: Long, f6: Float, f7: Double, f8: String)
case class C2(f1: String, f2: Double, f3: Float, f4: Long, f5: Int, f6: Char, f7: Short, f8: Byte)

The problem with type level programming is that you can do mostly naive algorithms and often end up with quadratic worst case complexity.

@Ssstlis
Copy link

Ssstlis commented Mar 16, 2020

Should we close this issue as PR as well?

@joroKr21
Copy link
Collaborator

Fixed by #682

@joroKr21 joroKr21 added this to the shapeless-2.4.0 milestone Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants