Scala Programming Language
  1. Scala Programming Language
  2. SI-7149

Reduce memory consumption of Types.uniques by using WeakHashSet

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      I experimented with making Types.uniques a weak hashset in this branch:
      https://github.com/gkossakowski/scala/tree/weak-unique-types

      I was using Yourkit to measure memory consumption (through strong references) after a few phases while doing quick.lib and quick.comp. Here are my results:

      Phase		Regular		Optimized	Gain
      typer		145			114	31 (21%)
      erasure		241			179	62 (25%)
      cleanup		281			217	64 (22%)
      
      Numbers for quick.comp
      ======================
      Phase		Regular		Optimized	Gain
      typer		225			188	37 (16%)
      erasure		329			275	54 (16%)
      cleanup		370			319	51 (13%)
      

      Optimized here means we used locker build out of the following commit:
      https://github.com/gkossakowski/scala/commit/85c8e269769a8ee3bcb57d800a7125389da8cbc7

      which uses a copy of Java's WeakHashMap. The reason I had to copy the whole implementation of WeakHashMap is that we need an access to getEntry method which is package protected so there's no other option to just copy that class (and some of its dependencies) to our own package. That was meant just to try the idea.

      It looks like we'll need to implement our own WeakHashSet one way or another. If we go down that route we might be able to squeeze a little bit more of memory because we don't need value field in Entry object for sets.

      Implementing my own collection is a bigger task that I can spend time on right now so I just leave this ticket open were we have potential benefits documented.

        Issue Links

          Activity

          Hide
          Grzegorz Kossakowski added a comment -
          Show
          Grzegorz Kossakowski added a comment - Fixed by http://github.com/scala/scala/pull/2605
          Hide
          Jason Zaugg added a comment -

          Backported to 2.10.3

          Show
          Jason Zaugg added a comment - Backported to 2.10.3

            People

            • Assignee:
              James Iry
              Reporter:
              Grzegorz Kossakowski
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development