forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Each `Pickle` object previously contained an `index` and `entries`, which are only used to populate the raw pickle bytes. Profiles show this as a significant source of allocations in some runs, and since the arrays backing these collections are held until jvm, the memory is likely to survive for several garbage collections and be tenured into an older space. Since the `bytes` array is the actual result of the pickling, this commit moves the other large (mutable!) collections to the pickler phase factory itself, and arranges that they be cleared before use and replaced at the end of each pickler phase (so as not to retain the memory for longer than needed). As a sanity check, each pickle has a field `active` which is used to assert that accesses to both mutable fields is safe -- it's set to false when they're cleared. The new override of `clear` in `AnyRefMap` is safe, since scala itself currently generates calls to `AnyRefMap.clear` when asked to: ``` [nix-shell:/code/scala/sandbox]$ scala -version Scala code runner version 2.12.9 -- Copyright 2002-2019, LAMP/EPFL and Lightbend, Inc. [nix-shell:/code/scala/sandbox]$ cat Test.scala object Test extends App { val map = new collection.mutable.AnyRefMap[String, Int]() map("a") = 0 map.clear() } [nix-shell:/code/scala/sandbox]$ scalac Test.scala -d . [nix-shell:/code/scala/sandbox]$ javap -c Test\$.class | grep '\.clear' 28: invokevirtual #87 // Method scala/collection/mutable/AnyRefMap.clear:()V ```
- Loading branch information
Showing
3 changed files
with
106 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters