Storing facts currently (as of PDB 5.x) works like this:
Get the value hashes for everything in the stored factset
Compute the hashes for everything in the new factset
Compare them
Store new values for whatever is different or new
Postgres 9.6 has support for upsert (INSERT ON CONFLICT UPDATE), which could let us do things better.
Store all values in a single upsert statement, rather than using separate updates and inserts.
We may be able to forego the local hash comparison, instead sending all values in a single upsert statement that is set up to only store values if they have changed.