From 3710d28925e2960e1ee164df3b4ce920f0b27319 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 15 Dec 2012 07:32:06 +1030 Subject: [PATCH] tal: don't always allocate an array in the samba benchmark. Since we added the length property, this penalizes us with an extra alloc. Unfortunately, we can't tell from the talloc.dump which are array tallocs and which are single tallocs, but grepping the sources gives a rate of 1 in 27. Signed-off-by: Rusty Russell --- ccan/tal/benchmark/samba-allocs.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/ccan/tal/benchmark/samba-allocs.c b/ccan/tal/benchmark/samba-allocs.c index 853b1fb2..e25c7e9b 100644 --- a/ccan/tal/benchmark/samba-allocs.c +++ b/ccan/tal/benchmark/samba-allocs.c @@ -141,8 +141,14 @@ static int unused_talloc_destructor(void *p) static void do_tallocs(struct node *node) { unsigned int i; - - node->n = talloc_size(node->parent ? node->parent->n : NULL, node->len); + static int count; + + if (count++ % 16 == 0) + node->n = talloc_array(node->parent ? node->parent->n : NULL, + char, node->len); + else + node->n = talloc_size(node->parent ? node->parent->n : NULL, + node->len); if (node->destructor) talloc_set_destructor(node->n, unused_talloc_destructor); if (node->name) @@ -169,9 +175,18 @@ static void unused_tal_destructor(void *p) static void do_tals(struct node *node) { unsigned int i; + static int count; + + /* Tal pays a penalty for arrays, but we can't tell which is an array + * and which isn't. Grepping samba source gives 1221 talloc_array of + * 33137 talloc occurrences, so conservatively assume 1 in 16 */ + if (count++ % 16 == 0) + node->n = tal_arr(node->parent ? node->parent->n : NULL, + char, node->len); + else + node->n = tal_alloc_(node->parent ? node->parent->n : NULL, + node->len, false, TAL_LABEL(type, "")); - node->n = tal_arr(node->parent ? node->parent->n : NULL, - char, node->len); if (node->destructor) tal_add_destructor(node->n, unused_tal_destructor); if (node->name) -- 2.39.2