I’m working on a mobile app and i want to optimise the data that it’s receiving from the server (as JSON).
There are 3 lists returned (each containing its own class of objects, the approximate list sizes are 50, 100 and 170). Each object has a Guid id and there is some relation data for each object. E.g.:
o = { Id = "8f088552-5b24-4ba4-a6e5-8958c4353581",
RelatedIds = ["19d2e562-0874-473f-8e05-7052e8defd9a", "615b4c47-199a-4f7d-8268-08ed43d9c891", ... ] }
Is there a way to compress these Guids to something sorter without storing an identity map? Perhaps using a hash function?
No. One of the attributes of (non-cryptographic) hashes is that they collide:
hash(a) == hash(b)buta != b. They are a performance optimization in the case where you are doing a lot of equality checks and you expect many false results (because ifhash(a) != hash(b)thena != b). A GUID->counter map is probably the best way to get smaller ids here.