From 8a9d23e4462aa19a17a3de463ff8e408656057af Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Tue, 29 Sep 2015 20:41:29 +0200 Subject: prioq: never shuffle identical entries Skip shuffling identical entries in shuffle_up(), just like we already do in shuffle_down(). --- src/basic/prioq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/basic/prioq.c b/src/basic/prioq.c index b89888be0e..5e567b181d 100644 --- a/src/basic/prioq.c +++ b/src/basic/prioq.c @@ -101,7 +101,7 @@ static unsigned shuffle_up(Prioq *q, unsigned idx) { k = (idx-1)/2; - if (q->compare_func(q->items[k].data, q->items[idx].data) < 0) + if (q->compare_func(q->items[k].data, q->items[idx].data) <= 0) break; swap(q, idx, k); -- cgit v1.2.3-54-g00ecf From 6fe869c251790a0e3cef5b243169dda363723f49 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Tue, 29 Sep 2015 20:56:17 +0200 Subject: sd-event: don't provide priority stability Currently, we guarantee that if two event-sources with the same priority fire at the same time, they're always dispatched in the same order. While this might sound nice in theory, there's is little benefit in providing stability on that level. We have no control over the order the events are reported, hence, we cannot guarantee that we get notified about both at the same time. By dropping the stability guarantee, we loose roughly 10% Heap swaps in the prioq on a desktop cold-boot. Krzysztof Kotlenga even reported up to 20% on his tests. This sounds worth optimizing, so drop the stability guarantee. --- src/libsystemd/sd-event/sd-event.c | 30 ------------------------------ 1 file changed, 30 deletions(-) (limited to 'src') diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 48a5219275..1a82c4c940 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -242,12 +242,6 @@ static int pending_prioq_compare(const void *a, const void *b) { if (x->pending_iteration > y->pending_iteration) return 1; - /* Stability for the rest */ - if (x < y) - return -1; - if (x > y) - return 1; - return 0; } @@ -277,12 +271,6 @@ static int prepare_prioq_compare(const void *a, const void *b) { if (x->priority > y->priority) return 1; - /* Stability for the rest */ - if (x < y) - return -1; - if (x > y) - return 1; - return 0; } @@ -310,12 +298,6 @@ static int earliest_time_prioq_compare(const void *a, const void *b) { if (x->time.next > y->time.next) return 1; - /* Stability for the rest */ - if (x < y) - return -1; - if (x > y) - return 1; - return 0; } @@ -343,12 +325,6 @@ static int latest_time_prioq_compare(const void *a, const void *b) { if (x->time.next + x->time.accuracy > y->time.next + y->time.accuracy) return 1; - /* Stability for the rest */ - if (x < y) - return -1; - if (x > y) - return 1; - return 0; } @@ -370,12 +346,6 @@ static int exit_prioq_compare(const void *a, const void *b) { if (x->priority > y->priority) return 1; - /* Stability for the rest */ - if (x < y) - return -1; - if (x > y) - return 1; - return 0; } -- cgit v1.2.3-54-g00ecf