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

Use WeakHashSet instead of HashSet for hash-consing types #12935

Merged
merged 2 commits into from
Jul 6, 2021

Commits on Jun 25, 2021

  1. Make util.WeakHashSet a subclass of util.MutableSet

    Thus making it a drop-in replacement for util.HashSet which will be
    useful in the next commit where we'll use it in Uniques.
    
    Also add `@constructorOnly` annotations for clarity.
    
    Also remove all existing references to WeakHashSet in the code base
    since it turns out they were all dead code.
    smarter committed Jun 25, 2021
    Configuration menu
    Copy the full SHA
    82cd467 View commit details
    Browse the repository at this point in the history
  2. Use WeakHashSet instead of HashSet for hash-consing types

    This mimics what Scala 2 has been doing for a long time now and serves
    the same purpose: it considerably reduces peak memory usage when
    compiling some projects, for example previously compiling the Scalatest
    tests required a heap of at least 11 GB, but now it fits in about 4 GB.
    
    This required changing the implementation of WeakHashSet to have
    overridable `hash` and `isEqual` methods just like HashSet, it also
    required making various private methods protected since NamedTypeUniques
    and AppliedUniques contain an inlined implementation of `put`.
    
    This commit also changes the default load factor of a WeakHashSet from
    0.75 to 0.5 to match the load factor we use for HashSets, though note that
    Scala 2 has always been using 0.75.
    
    For a history of the usage of WeakHashSet in Scala 2 see:
    - scala/scala#247
    - scala/scala#2605
    - scala/scala#2901
    smarter committed Jun 25, 2021
    Configuration menu
    Copy the full SHA
    f36f95b View commit details
    Browse the repository at this point in the history