Saturday, November 27, 2010

Re: Emacs' Org-mode clone for Vim

On Nov 27, 1:45 pm, ZyX <zyx....@gmail.com> wrote:

> 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.

What I was wondering was whether each key is stored as part of a hash
table for the dictionary, where reference internally was by the hash
rather than by the text of the key itself. In that case it seems as
though memory use would be virtually unaffected by length of the key,
but maybe I'm misunderstanding.

In any case, I did run some tests and it looks like memory usage is
increased by same amount as the length of the strings. The
interesting thing is that the extra memory usage is negligible in
comparison to the overhead of the dict structure itself.

Here's roughly what I see:

DIctionary with 1,000,000 entries each holding a dict with a single
one-character key: {'entry1': : {'k':'1'}} . .. .
appears to increase my gvim memory usage from 5MB to 295MB:

let d={}
let i = 0
while i < 1000000
let d[i]={ 'k':'1'
let i +=1
endwhile


Same dictionary with 20 char text keys (e.g., {'entry1': :
{'k1234567890123456789':'1'}} )
results in total memory usage of around 310MB. And just the text of
the keys is 20 chars * 1,000,000 entries, or 20MB, so roughly
correlates with what I see.

As number of keys in the subdict go up, memory usage of the dict
structure rises a lot regardless of how long the key strings are.
E.g., with 10 one-char keys in subdict, memory usage rises from 5MB to
680MB.

I've been hesitating to use long keys in large dictionaries but I
won't worry about it anymore. I also won't worry generally about
using my measly 10k to 50k entry dictionaries, I think Vim can handle
them easily.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment