I saw in the code that the bucket stores, in the same byte array, both the keys and the values. And it does something like this, for example if only 2 key value pairs are present: Key1, Key2, Emtpy, … Empty, Value1, Value2, Empty, … Empty.
This storing in the same byte array is done because of address alignment guarantees. I understand that if it were to store key1, value1, key2, value2,… then there could be some padding, between each key&value, due to address alignment guarantees.
However, why does it not simply have a byte array for the 8 keys and another one for the 8 values ? There will no longer be a possible padding between the key section and values section.
Why was this single array version been chosen ? Does anyone have any idea ?
This might be for performance. By keeping keys and values contiguous in memory they may fit in a single cache memory entry. In one load, you would get key and values. By keeping them separate, one would not be able to benefit from this.
I guess this decision has been made based on benchmarks.