Deduplicate entities in serialized history

Fixes #1403
Save history more frequently (#1345)