rorygraves / scalac_perf

The Scala programming language
http://www.scala-lang.org/
16 stars 3 forks source link

special apply methods #42

Open mkeskells opened 6 years ago

mkeskells commented 6 years ago

the compiler handles List.apply() specially (with 0 args)

consider and discuss with @retronym i fthis is valid for other cases

e.g list.apply with explicit args

Seq, Set, Map for 0 args

hrhino commented 6 years ago

Note that Array(x, y) is already optimized to { val tmp = new Array(2); tmp(0) = x; tmp(1) = y; tmp }

rorygraves commented 6 years ago

Steps:

  1. How often to these cases occur
  2. What cases are worth optimising
  3. Apply changes as appropriate.
mkeskells commented 6 years ago

appropriate is based on safety, bytecode size and benchmarking

retronym commented 6 years ago

For reference, here's a WIP compiler rewrite that unrolls small List(a, b, c .. ) into a :: b :: .. :: Nil

The resulting bytecode would be cleaner with runtime support, rewrite to ScalaRuntime.list_apply_5(a, b, c, d, e), as suggested by this ticket.

Just adding in actual overloads of List.apply is a bit problematic because overload can interfere with type inference.

retronym commented 6 years ago

Also worth noting that not all of the innefficiency of List.apply at the moment comes from the packing the elements into varargs array. The generic result building code used internally will be replaced by a specialized version for List in 2.13.x.

mkeskells commented 6 years ago

So we look at this for the 2.13 branch primarily - labelled as such.

We also cant add to the List.apply because we have no way to disambiguate List.apply _ I had a email chain from a few years ago, predating the List() rewrite I think

mkeskells commented 6 years ago

Hi @retronym Just noticed the date of the 'WIP compiler rewrite' Nov 3 2013 - is that when we had the List() discussion?

How many other nuggets of stalled work do you have hidden away needing some affection from us :scream: