Size of a map key in words

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Size of a map key in words

Grzegorz Junka
What's the size of a single key in an Erlang map in words? Is there any
information how the hash function works?

Grzegorz

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Size of a map key in words

Michael Truog
On 06/29/2017 03:48 PM, Grzegorz Junka wrote:
> What's the size of a single key in an Erlang map in words? Is there any information how the hash function works?
>
> Grzegorz
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>
http://erlang.org/doc/efficiency_guide/advanced.html#id68923 has the memory information and https://github.com/okeuday/erlang_term shows how to get this size during runtime.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Size of a map key in words

Richard A. O'Keefe-2

> On 30/06/2017, at 12:23 PM, Michael Truog <[hidden email]> wrote:
>>
>>
> http://erlang.org/doc/efficiency_guide/advanced.html#id68923 has the memory information and https://github.com/okeuday/erlang_term shows how to get this size during runtime.

Those two disagree.  For example, erlang_term says
Small Map (N =< 32):
  4 words + 2 words per key/value pair + the size of each pair
whereas advanced.html says
Small Map
  5 words + the size of all keys and values.

The latter just *has* to be wrong, the former is at least believable.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Size of a map key in words

Michael Truog
On 06/29/2017 06:13 PM, Richard A. O'Keefe wrote:

>> On 30/06/2017, at 12:23 PM, Michael Truog <[hidden email]> wrote:
>>>
>> http://erlang.org/doc/efficiency_guide/advanced.html#id68923 has the memory information and https://github.com/okeuday/erlang_term shows how to get this size during runtime.
> Those two disagree.  For example, erlang_term says
> Small Map (N =< 32):
>    4 words + 2 words per key/value pair + the size of each pair
> whereas advanced.html says
> Small Map
>    5 words + the size of all keys and values.
>
> The latter just *has* to be wrong, the former is at least believable.
>
The erlang_term README information is based on an older version of the Erlang Efficiency guide html docs and the newer content is different.  It is possible an error was inserted into the new html docs, but it would be best for the Erlang/OTP team to check this.


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Size of a map key in words

Lukas Larsson-8


On Fri, Jun 30, 2017 at 4:59 AM, Michael Truog <[hidden email]> wrote:
On 06/29/2017 06:13 PM, Richard A. O'Keefe wrote:
On 30/06/2017, at 12:23 PM, Michael Truog <[hidden email]> wrote:

http://erlang.org/doc/efficiency_guide/advanced.html#id68923 has the memory information and https://github.com/okeuday/erlang_term shows how to get this size during runtime.
Those two disagree.  For example, erlang_term says
Small Map (N =< 32):
   4 words + 2 words per key/value pair + the size of each pair
whereas advanced.html says
Small Map
   5 words + the size of all keys and values.

The latter just *has* to be wrong, the former is at least believable.

The erlang_term README information is based on an older version of the Erlang Efficiency guide html docs and the newer content is different.  It is possible an error was inserted into the new html docs, but it would be best for the Erlang/OTP team to check this.


The latter is the correct value. The documentation for both small and large map sizes was incorrect and fixed in OTP-19.3 (I think).

Small map size = boxed ptr + header + size + key ptr + key header = 5 words.

The old incorrect version did not count the boxed ptr as part of the term size.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Size of a map key in words

Sverker Eriksson-4
In reply to this post by Grzegorz Junka

On 06/30/2017 12:48 AM, Grzegorz Junka wrote:


> Is there any information how the hash function works?
>

Hashing is only used for maps with more than 32 keys.

It's implemented in C here:
https://github.com/erlang/otp/blob/OTP-20.0/erts/emulator/beam/utils.c#L1581


/Sverker

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Loading...