I am not sure if using Generics is a best shot at achieving high performance. My best bet would actually be writing your own instance for Serializable like this:
instance (Serializable a) => Serializable (HashMap a) where
...
To avoid creating orphan instances you can use newtype trick:
newtype SerializableHashMap a = SerializableHashMap { toHashMap :: HashMap a }
instance (Serializable a) => SerializableHashMap a where
...
The question is how to define ...
?
There is no definite answer before you actually try and implement and benchmark possible solutions.
One possible solution is to use toList
/fromList
functions and store/read the size of the HashMap
.
The other (which would be similar to using Generics) would be to write direct serialization based on internal HashMap structure. Given the fact that you dont really have the internals exported that would be a job for Generics only.