Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Misc Compiler, Misc Library
    • Labels:

      Description

      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-rr- 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-rr- 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.

        Issue Links

          Activity

          Hide
          Commit Message Bot added a comment -

          (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 SI-5096, SI-5097.

          Show
          Commit Message Bot added a comment - (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 SI-5096 , SI-5097 .

            People

            • Assignee:
              Unassigned
              Reporter:
              Todd Vierling
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development