Custom room properties keys length OR value length?

I was wondering which is better in custom room properties , creating 10 keys with a value byte for each key , or creating 1 key with value byte array of size 10?
Any help would be awesome :smiley:

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @RamyDergham,

    Here is what I think:

    If you are going to frequently change those properties, 10 keys is better since you can change and update each key/value separately.
    Otherwise one key/value is better in case this won't change that often.

    Also 10 keys may be better for CAS (Check-And-Swap).
  • What about size in bytes? Which is better?
  • Kaiserludi
    Kaiserludi admin
    edited August 2017

    What about size in bytes? Which is better?

    10 keys (which each also have some size) + 10 values that are 1 byte in size each, results in 10 times the average size of your keys + 10 bytes for the values + 10 extra bytes to store the types of the values.

    1 key + 1 value results in 1 times the average size of your keys + 10 bytes for the values + 5 extra bytes (1 for the info that it is a byte array + 4 for the byte array size).

    So the exact difference depends on the size of your key (a key string "a" obviously needs less bytes than a key string "I am a much longer string"), but even with short keys the overhead for additional keys gets more significant the smaller the values are.

    So when you always need all the data at once, then 1 key with a big value is clearly much better than lots of keys with tiny values

    However keep in mind that when you only every need to access some of the data and never all of it at once, then splitting the data into multiple properties quickly makes more sense in terms of bandwidth than one huge property. Better for example have 10 properties with 20 bytes each than 1 property with 100 bytes, as although the former overall means 200 bytes for the sum of all properties, it means that when you need to access just one property, only 20 bytes need to be transferred, while in the latter case still all the 100 bytes need to be transferred.

    So as @JohnTube has already explained:
    All data that will be changed at the same time should be part of the same property and other data that will be changed independently should be part of a separate property.

    Conclusion:
    There really is no single best option that works in all usage scenarios - what is better totally depends on your specific use case.