Open mkeskells opened 6 years ago
Note that Array(x, y)
is already optimized to { val tmp = new Array(2); tmp(0) = x; tmp(1) = y; tmp }
Steps:
appropriate is based on safety, bytecode size and benchmarking
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.
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.
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
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:
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