ditto
ditto copied to clipboard
Allow Site ID to be more Generic
It would be nice if Site ID was not limited to u32 as a datatype, and instead could be anything that implements the traits needed to function. (I.e, Serde traits + Eq and Hash). I'm not sure how tightly coupled the implementation is to u32 at the moment.
This would allow a more decentralised approach at Site IDs, by using something such as a Random UUID to be used in place of a u32
Site IDs are limited to compact types like u32 because they are included in the UID of each CRDT element (i.e. a List with 100 elements requires 100 site IDs). Larger site IDs like UUIDs create more overhead per element (4 bytes vs 16 bytes).
One workaround may be to use u32 internally and another value (like a UUID or even a generic hashable type) externally, and maintain a map between them. This would add complexity to the codebase but if it's a popular need I could see adding it.
I was thinking have it generic, so you could use u32, usize, u64, i64, etc.. whatever you felt the need to be, but I guess a simple mapping may work.
I think the use case here would be randomly assigned site IDs with low probability of collision. A u64 allows for 1 billion users with a collision probability on the order of 5e-10.
I understand what you're saying about the overhead problem but I took a look at the implementation and because you used a newtype it seems like it would be very straightforward to add a cargo feature for which type you want to use using conditional compilation.
For the simplicity tradeoff of using u64 to randomly assign site ids I think decentralized software coders would happily take the memory tradeoff then optimize later with raft etc if need be.
Instead of a UUID, I would rather use a public address such as the public address of an Ethereum wallet. This ways, we can associate the data with a decentralized wallet/smart contract.
I get the idea of a map that associates the SiteId to something else. But it means that this map has to be stored decentralized also. So one would do that with the map CRDT?