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

Add scala.runtime.AbstractPartialFunction #5096

Closed
scabug opened this issue Oct 19, 2011 · 2 comments
Closed

Add scala.runtime.AbstractPartialFunction #5096

scabug opened this issue Oct 19, 2011 · 2 comments

Comments

@scabug
Copy link

scabug commented Oct 19, 2011

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.

@scabug
Copy link
Author

scabug commented Oct 19, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5096?orig=1
Reporter: Todd Vierling (tvierling)
Blocks #5097
Attachments:

@scabug
Copy link
Author

scabug commented Oct 19, 2011

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.

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

1 participant