You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The attached diff implements a PartialFunction analogue to scala.runtime.AbstractFunctionN. It takes the smallest possible footprint approach to the change, to avoid any possibility of a bare match block being interpreted as a plain Function (rather than properly a PartialFunction).
This trims about 9k of uncompressed class file size from every bare match block used as a PF. It may well speed up the use of PFs, as well, since all the trait stubs are reified in the AbstractPF class and not in every PF.
For scala-library.jar, this reduces total size a very minor amount (60k):
The gain is much more likely to be noticeable with Lift or other frameworks that work heavily with bare match blocks as PFs. I plan on submitting diffs under separate cover to make explicit use of scala.runtime.AbstractPartialFunction, to trim related cases where code is explicitly inheriting from the PF trait today.
The text was updated successfully, but these errors were encountered:
Commit Message Bot (anonymous) said:
(extempore in r25854) AbstractPartialFunction.
Contributed by Todd Vierling with minor mods by extempore. This is an
obvious extension of AbstractFunctionN which I had some issue making
work at the time. Sounds kind of pitiful given that the compiler patch
is about two lines, but let's all agree to believe it was a different
world then.
This example program is impacted as follows:
class A {
def f: PartialFunction[Any, Int] = { case x: String => 1 }
def g: PartialFunction[Any, Int] = f orElse { case x: List[_] => 2 }
def h: PartialFunction[Any, Int] = g orElse { case x: Set[_] => 3 }
}
Before: 34943 bytes of bytecode
After: 4217 bytes of bytecode
A mere 88% reduction in size. "'Tis but a trifle!" Closes #5096, #5097.
The attached diff implements a PartialFunction analogue to scala.runtime.AbstractFunctionN. It takes the smallest possible footprint approach to the change, to avoid any possibility of a bare match block being interpreted as a plain Function (rather than properly a PartialFunction).
This trims about 9k of uncompressed class file size from every bare match block used as a PF. It may well speed up the use of PFs, as well, since all the trait stubs are reified in the AbstractPF class and not in every PF.
For scala-library.jar, this reduces total size a very minor amount (60k):
$ ls -l dists/scala-2.10.0.r25850-b20111018225736/lib/scala-library.jar
-rw-r--r-- 1 tvierling tvierling 8697074 2011-10-18 23:13 dists/scala-2.10.0.r25850-b20111018225736/lib/scala-library.jar
$ ls -l build/pack/lib/scala-library.jar
-rw-r--r-- 1 tvierling tvierling 8633048 2011-10-19 15:25 build/pack/lib/scala-library.jar
The gain is much more likely to be noticeable with Lift or other frameworks that work heavily with bare match blocks as PFs. I plan on submitting diffs under separate cover to make explicit use of scala.runtime.AbstractPartialFunction, to trim related cases where code is explicitly inheriting from the PF trait today.
The text was updated successfully, but these errors were encountered: