Improved the pickler: reduced execution time and output size.

The idea is to merge under a single Ref multiple entities that
are == to each other. We apply this to all value-behaved entities,
as well as arities.