]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Minor tweaks
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 18 Aug 2021 15:11:49 +0000 (10:11 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 18 Aug 2021 15:37:27 +0000 (10:37 -0500)
src/lib/util/heap.c
src/lib/util/lst.c
src/lib/util/lst_tests.c

index bca3a65bad942a322bd921837675a9facf81758d..a69000f67847a6cbc9a2bd402025093685043703 100644 (file)
@@ -83,17 +83,27 @@ fr_heap_t *_fr_heap_alloc(TALLOC_CTX *ctx, fr_heap_cmp_t cmp, char const *type,
         *      element count, assume expanding past
         *      that size is going to be the uncommon
         *      case.
+        *
+        *      We seem to need two headers here otherwise
+        *      we overflow the pool, and we get a
+        *      significant slowdown in allocation performance.
         */
        if (init) {
-               hp = talloc_zero_pooled_object(ctx, fr_heap_t, 1, sizeof(void *) * init);
+               hp = talloc_pooled_object(ctx, fr_heap_t, 2, sizeof(void *) * init);
        } else {
                init = INITIAL_CAPACITY;
-               hp = talloc_zero(ctx, fr_heap_t);
+               hp = talloc(ctx, fr_heap_t);
        }
        if (unlikely(!hp)) return NULL;
 
-       hp->size = init;
-       hp->p = talloc_array(hp, void *, hp->size);
+       *hp = (fr_heap_t){
+               .size = init,
+               .p = talloc_array(hp, void *, init),
+               .type = type,
+               .cmp = cmp,
+               .offset = offset
+       };
+
        if (unlikely(!hp->p)) {
                talloc_free(hp);
                return NULL;
@@ -106,9 +116,6 @@ fr_heap_t *_fr_heap_alloc(TALLOC_CTX *ctx, fr_heap_cmp_t cmp, char const *type,
         *      into the heap.
         */
        hp->p[0] = (void *)UINTPTR_MAX;
-       hp->type = type;
-       hp->cmp = cmp;
-       hp->offset = offset;
 
        return hp;
 }
index 11a6861cbdbab7baa288e1f9aa6f9f3bf87f8bcd..36b5ee50a5f7de541a723de0f011d76a2d3c9d27 100644 (file)
@@ -231,8 +231,11 @@ fr_lst_t *_fr_lst_alloc(TALLOC_CTX *ctx, fr_lst_cmp_t cmp, char const *type, siz
         *      If we pre-allocated the array of elements
         *      we'd end up wasting that memory as soon as
         *      we needed to expand the array.
+        *
+        *      Pre-allocating three chunks appears to be
+        *      the optimum.
         */
-       lst = talloc_zero_pooled_object(ctx, fr_lst_t, 2, (INITIAL_STACK_CAPACITY * sizeof(fr_lst_index_t)));
+       lst = talloc_zero_pooled_object(ctx, fr_lst_t, 3, (INITIAL_STACK_CAPACITY * sizeof(fr_lst_index_t)));
        if (unlikely(!lst)) return NULL;
 
        lst->capacity = INITIAL_CAPACITY;
index 49f1cea05b9b85cb0cb36e0016bff63be2aacb2b..40969eae3a8cc1d1e76232cc5b2c19d223aadd49 100644 (file)
@@ -445,9 +445,9 @@ static void lst_heap_cmp(void)
        end_lst_pop = fr_time();
 
        TEST_MSG_ALWAYS("\nlst size: %zu\n", NUM_ELEMENTS(values));
-       TEST_MSG_ALWAYS("alloc: %"PRIu64" ns\n", end_lst_alloc - start_lst_alloc);
-       TEST_MSG_ALWAYS("insert: %"PRIu64" ns\n", end_lst_insert - start_lst_insert);
-       TEST_MSG_ALWAYS("pop: %"PRIu64" ns\n", end_lst_pop - start_lst_pop);
+       TEST_MSG_ALWAYS("alloc: %"PRIu64" μs\n", (end_lst_alloc - start_lst_alloc) / 1000);
+       TEST_MSG_ALWAYS("insert: %"PRIu64" μs\n", (end_lst_insert - start_lst_insert) / 1000);
+       TEST_MSG_ALWAYS("pop: %"PRIu64" μs\n", (end_lst_pop - start_lst_pop) / 1000);
 
        talloc_free(lst);
 
@@ -457,7 +457,7 @@ static void lst_heap_cmp(void)
        populate_values(values, NUM_ELEMENTS(values));
 
        start_heap_alloc = fr_time();
-       heap = fr_heap_alloc(NULL, lst_cmp, lst_thing, idx, 0);
+       heap = fr_heap_alloc(NULL, lst_cmp, lst_thing, idx, NUM_ELEMENTS(values));
        end_heap_alloc = fr_time();
        TEST_CHECK(heap != NULL);
 
@@ -474,9 +474,9 @@ static void lst_heap_cmp(void)
        end_heap_pop = fr_time();
 
        TEST_MSG_ALWAYS("\nheap size: %zu\n", NUM_ELEMENTS(values));
-       TEST_MSG_ALWAYS("alloc: %"PRIu64" ns\n", end_heap_alloc - start_heap_alloc);
-       TEST_MSG_ALWAYS("insert: %"PRIu64" ns\n", end_heap_insert - start_heap_insert);
-       TEST_MSG_ALWAYS("pop: %"PRIu64" ns\n", end_heap_pop - start_heap_pop);
+       TEST_MSG_ALWAYS("alloc: %"PRIu64" μs\n", (end_heap_alloc - start_heap_alloc) / 1000);
+       TEST_MSG_ALWAYS("insert: %"PRIu64" μs\n", (end_heap_insert - start_heap_insert) / 1000);
+       TEST_MSG_ALWAYS("pop: %"PRIu64" μs\n", (end_heap_pop - start_heap_pop) / 1000);
 
        talloc_free(heap);
 }