darray: tweak parameters a bit for better memory usage

Here are some quick numbers from valgrind, running rulescomp only with a
simple, common "us,de" rule set:

before darray: cb047bb
total heap usage: 44,924 allocs, 44,924 frees, 3,162,342 bytes allocated

after darray: c87468e
total heap usage: 52,670 allocs, 52,670 frees, 2,844,517 bytes allocated

tweaking specific inital allocation sizes:
total heap usage: 52,652 allocs, 52,652 frees, 2,841,814 bytes allocated

changing initial alloc = 2 globally
total heap usage: 47,802 allocs, 47,802 frees, 2,833,614 bytes allocated

changing initial alloc = 3 globally
total heap usage: 47,346 allocs, 47,346 frees, 3,307,110 bytes allocated

changing initial alloc = 4 globally
total heap usage: 44,643 allocs, 44,643 frees, 2,853,646 bytes allocated

[ Changing the geometric progression constant from 2 only made things
worse. I tried the golden ratio - not so golden :) ]

The last one is obviously the best, so it was chosen, with the specific
tweaks thrown in as well (these were there before but don't make much
difference). Overall it seems to do better than the previous manual
allocations which is a bit surprising.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-05-30 15:55:21 +03:00
parent 93ef256063
commit 57f184e218
4 changed files with 7 additions and 4 deletions

View File

@ -93,6 +93,8 @@ atom_table_new(void)
if (!table) if (!table)
return NULL; return NULL;
darray_init(table->table);
darray_growalloc(table->table, 100);
darray_append(table->table, NULL); darray_append(table->table, NULL);
return table; return table;

View File

@ -280,7 +280,7 @@ typedef darray(unsigned long) darray_ulong;
static inline size_t darray_next_alloc(size_t alloc, size_t need) static inline size_t darray_next_alloc(size_t alloc, size_t need)
{ {
if (alloc == 0) if (alloc == 0)
alloc = 1; alloc = 4;
while (alloc < need) while (alloc < need)
alloc *= 2; alloc *= 2;
return alloc; return alloc;

View File

@ -992,10 +992,13 @@ load_rules(FILE *file)
rules = calloc(1, sizeof(*rules)); rules = calloc(1, sizeof(*rules));
if (!rules) if (!rules)
return NULL; return NULL;
darray_init(rules->rules);
darray_growalloc(rules->rules, 16);
memset(&mapping, 0, sizeof(mapping)); memset(&mapping, 0, sizeof(mapping));
memset(&tgroup, 0, sizeof(tgroup)); memset(&tgroup, 0, sizeof(tgroup));
darray_init(line); darray_init(line);
darray_growalloc(line, 128);
while (input_line_get(file, &line)) { while (input_line_get(file, &line)) {
if (match_line(&line, &mapping, &trule, &tgroup)) { if (match_line(&line, &mapping, &trule, &tgroup)) {

View File

@ -256,8 +256,6 @@ typedef struct _ModMapEntry
} u; } u;
} ModMapEntry; } ModMapEntry;
#define SYMBOLS_INIT_SIZE 110
typedef struct _SymbolsInfo typedef struct _SymbolsInfo
{ {
char *name; /* e.g. pc+us+inet(evdev) */ char *name; /* e.g. pc+us+inet(evdev) */
@ -286,7 +284,7 @@ InitSymbolsInfo(SymbolsInfo * info, struct xkb_keymap *keymap)
info->fileID = 0; info->fileID = 0;
info->merge = MergeOverride; info->merge = MergeOverride;
darray_init(info->keys); darray_init(info->keys);
darray_growalloc(info->keys, SYMBOLS_INIT_SIZE); darray_growalloc(info->keys, 110);
info->modMap = NULL; info->modMap = NULL;
for (i = 0; i < XkbNumKbdGroups; i++) for (i = 0; i < XkbNumKbdGroups; i++)
info->groupNames[i] = XKB_ATOM_NONE; info->groupNames[i] = XKB_ATOM_NONE;