Skip to content

Reduce memory consumption of Types.uniques by using WeakHashSet #7149

@scabug

Description

@scabug

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:
gkossakowski/scala@85c8e26

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions