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 of compiletime tuple construction #15988

Closed
Katrix opened this issue Sep 7, 2022 · 0 comments · Fixed by #18013
Closed

Performance of compiletime tuple construction #15988

Katrix opened this issue Sep 7, 2022 · 0 comments · Fixed by #18013

Comments

@Katrix
Copy link
Contributor

Katrix commented Sep 7, 2022

Compiler version

3.2.0

Minimized example

Tuple construction through constValueTuple, summonAll and probably others too currently run in quadratic time at runtime, constructing all the smaller tuple sizes before getting to the desired one.

  def foo: (String, Int, Double, String, Boolean) =
    scala.compiletime.constValueTuple[("foo", 5, 3.14, "bar", false)]

Decompiled Java

   public Tuple5 foo() {
      String var2 = "foo";
      boolean var5 = true;
      double var8 = 3.14;
      String var12 = "bar";
      boolean var15 = false;
      Tuple.package.EmptyTuple Tuple_this = .MODULE$;
      Product res = (Tuple1)scala.runtime.Tuples..MODULE$.cons(BoxesRunTime.boxToBoolean(false), Tuple_this);
      Tuple1 Tuple_this = (Tuple1)res;
      Product res = (Tuple2)scala.runtime.Tuples..MODULE$.cons("bar", Tuple_this);
      Tuple2 Tuple_this = (Tuple2)res;
      Product res = (Tuple3)scala.runtime.Tuples..MODULE$.cons(BoxesRunTime.boxToDouble(3.14), Tuple_this);
      Tuple3 Tuple_this = (Tuple3)res;
      Product res = (Tuple4)scala.runtime.Tuples..MODULE$.cons(BoxesRunTime.boxToInteger(5), Tuple_this);
      Tuple4 Tuple_this = (Tuple4)res;
      Product res = (Tuple5)scala.runtime.Tuples..MODULE$.cons("foo", Tuple_this);
      return (Tuple5)res;
   }

Expectation

   public Tuple5 foo() {
      return scala.Tuple5..MODULE$.apply("foo", BoxesRunTime.boxToInteger(5), BoxesRunTime.boxToDouble(3.14), "bar", BoxesRunTime.boxToBoolean(false));
   }
@Katrix Katrix added the stat:needs triage Every issue needs to have an "area" and "itype" label label Sep 7, 2022
@TheElectronWill TheElectronWill added itype:enhancement itype:performance area:library Standard library and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 8, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 20, 2023
The new implementation instantiates the TupleN/TupleXXL classes directly.
This avoids the expensive construction of tuples using `*:`.

Fixes scala#15988
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 20, 2023
The new implementation instantiates the TupleN/TupleXXL classes directly.
This avoids the expensive construction of tuples using `*:`.

Fixes scala#15988
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 20, 2023
The new implementation instantiates the TupleN/TupleXXL classes directly.
This avoids the expensive construction of tuples using `*:`.

Fixes scala#15988
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 22, 2023
The new implementation instantiates the TupleN/TupleXXL classes directly.
This avoids the expensive construction of tuples using `*:`.

Fixes scala#15988
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 12, 2023
The new implementation instantiates the TupleN/TupleXXL classes directly.
This avoids the expensive construction of tuples using `*:`.

Fixes scala#15988
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 25, 2023
The new implementation instantiates the TupleN/TupleXXL classes directly.
This avoids the expensive construction of tuples using `*:`.

Fixes scala#15988
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 17, 2023
The new implementation instantiates the TupleN/TupleXXL classes directly.
This avoids the expensive construction of tuples using `*:`.

Fixes scala#15988
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Sep 19, 2023
The new implementation instantiates the TupleN/TupleXXL classes directly.
This avoids the expensive construction of tuples using `*:`.

Fixes scala#15988
nicolasstucki added a commit that referenced this issue Sep 25, 2023
The new implementation instantiates the TupleN/TupleXXL classes
directly.
This avoids the expensive unrolling of tuples using `*:` recursively.

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

Successfully merging a pull request may close this issue.

2 participants