summaryrefslogtreecommitdiffstats
path: root/ipc
diff options
context:
space:
mode:
authorKuan-Wei Chiu <visitorckw@gmail.com>2024-01-10 16:12:13 +0800
committerAndrew Morton <akpm@linux-foundation.org>2024-02-22 15:38:52 -0800
commitc641722e0c944e423572dd6222c677678d793ed5 (patch)
treec1caa1ad771be20efb81d696e26e14221e8eb247 /ipc
parentc499c717ee7cc07f47d7ee38a1791a58dcf1d4eb (diff)
downloadlinux-stable-c641722e0c944e423572dd6222c677678d793ed5.tar.gz
linux-stable-c641722e0c944e423572dd6222c677678d793ed5.tar.bz2
linux-stable-c641722e0c944e423572dd6222c677678d793ed5.zip
lib min_heap: optimize number of comparisons in min_heapify()
Optimize the min_heapify() function, resulting in a significant reduction of approximately 50% in the number of comparisons for large random inputs, while maintaining identical results. The current implementation performs two comparisons per level to identify the minimum among three elements. In contrast, the proposed bottom-up variation uses only one comparison per level to assess two children until reaching the leaves. Then, it sifts up until the correct position is determined. Typically, the process of sifting down proceeds to the leaf level, resulting in O(1) secondary comparisons instead of log2(n). This optimization significantly reduces the number of costly indirect function calls and improves overall performance. Link: https://lkml.kernel.org/r/20240110081213.2289636-3-visitorckw@gmail.com Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com> Acked-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'ipc')
0 files changed, 0 insertions, 0 deletions