sent 00:27:10 28 November 2010, Sunday
by hsitz:
> I have another performance-related (but unrelated to the clean-coding-
> practice issue) question about dicts that I've been wondering about.
> Does the length of the name assigned to a key affect memory usage?
> For example, in comparing the two dictionaries below, both of which
> have 1,000,000 entries, does the long name of the key affect memory
> usage?
>
> { 'entry_1': { 's1': 'text_for_s1'}, . . . 'entry_1000000': { 's1':
> 'text_for_s1'} }
>
>
> { 'entry_1': { '____________________________________s1':
> 'text_for_s1'}, . . . 'entry_1000000':
> { '_______________________________s1': 'text_for_s1'} }
>
> I guess I could just do the test myself, and I guess I will now, but
> if you know off the top of your head I'd be curious to hear more about
> these internal storage details for dicts.
If you want to know this, ask someone, who examined source code of vim because I
never did it. I can guess that variable and dictionary lookup functions use the
same mechanism, but I don't know it for sure. Long name will definitely affect
memory usage (because in the other case vim will require infinite memory for
every key), but I can't say whether it is O(n) or something else without
benchmarks. I can say that I used to hold up to 820 bytes in a single dictionary
key (for testing purposes) and everything worked fine.
No comments:
Post a Comment