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

performance issue with combined Length and ToSizedHList implicit derivation #1181

Closed
tnielens opened this issue May 31, 2021 · 3 comments
Closed

Comments

@tnielens
Copy link

There seems to be a performance problem with the combined implicit derivation of Length and ToSizedHList. When n grows, the compilation time becomes quickly unpractical. I reproduced the problem with shapeless 2.3.7 and scala 2.12.14/2.13.6 .

  val n = Nat(100)
  val f = Fill[n.N, String]

  def test[N <: Nat](implicit l: Length.Aux[f.Out, N], v: ToSizedHList[List, String, N]): Unit = {}

  // perf issue 
  test

  // no perf issue
  test[n.N]
  val l = Length[f.Out]
  ToSizedHList[List, String, l.Out]
@joroKr21
Copy link
Collaborator

implicit def instance[CC[T] <: Iterable[T], A, N <: Nat](
      implicit gt: IsRegularIterable[CC[A]],
               ac: AdditiveCollection[CC[A]],
               ti: ToInt[N], 
               th: ToHList[CC[A], N]
    ): Aux[CC, A, N, Option[th.Out]] =
      new ToSizedHList[CC, A, N] {
        type Out = Option[th.Out]
        def apply(as: CC[A]): Out =
          as.sized[N].map(_.toHList)
      }

ToInt and ToHList look in the wrong order to me

@joroKr21
Copy link
Collaborator

// no perf issue
test[n.N]

Ahh, so the problem is in type inference, not with the implicits 🤔

@joroKr21
Copy link
Collaborator

Fixed in #1182

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

No branches or pull requests

2 participants