You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
```
Avoid allocating
Some
s; just emitif (tag.runtimeClass.isInstance(scrutinee)) ...
The text was updated successfully, but these errors were encountered: