scala / collection-strawman

Implementation of the new Scala 2.13 Collections
Apache License 2.0
200 stars 72 forks source link

Uniform approach to serialization across collections #523

Closed retronym closed 6 years ago

retronym commented 6 years ago

Before shipping 2.13.0, we should come up with a uniform approach to serialization of collections.

To date, our approach has been -

We also need to use custom serialization to deal with objects whose hash code changes on deserialization. We do this in mutable.HashMap. It appears to be missing from mutable.{HashMap, ChampHashMap} at the moment.

IMO, our default approach should be serializing a tag with the collection type, collection type specific config data (e.g. loadFactor), and then the elements. Deserialization would build a new collection with these elements. Details like class Map1, or the precise field layout of HashCollisionMapNode could be changed while remaining serialization compatible.

However, there is a gotcha with custom serialization: https://github.com/scala/bug/issues/9237

In some classloader setups, we end up trying to deserialize the elements in the wrong classloader.

lrytz commented 6 years ago

cross-link https://github.com/scala/bug/issues/6654 and https://github.com/scala/bug/issues/7005 and https://github.com/scala/bug/issues/8576