From f03224d29d91bdbe2aef7432c4ca4a6290b1aa43 Mon Sep 17 00:00:00 2001 From: Richard Eklycke Date: Fri, 7 Jan 2022 14:46:46 +0100 Subject: [PATCH 1/2] Optimization: Preprocess files in parallel For large projects having many header files, I've seen very positive results. --- lib/ceedling/preprocessinator_helper.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ceedling/preprocessinator_helper.rb b/lib/ceedling/preprocessinator_helper.rb index 4bbda67fc..e91d3e633 100644 --- a/lib/ceedling/preprocessinator_helper.rb +++ b/lib/ceedling/preprocessinator_helper.rb @@ -1,3 +1,4 @@ +require 'ceedling/par_map' class PreprocessinatorHelper @@ -43,7 +44,12 @@ def preprocess_files_smartly(file_list, preprocess_file_proc) if (@configurator.project_use_deep_dependencies) @task_invoker.invoke_test_preprocessed_files(file_list) else - file_list.each { |file| preprocess_file_proc.call( yield(file) ) } + found_files = Array.new + file_list.each { |file| found_files << yield(file) } + + par_map(PROJECT_COMPILE_THREADS, found_files) do |file| + preprocess_file_proc.call(file) + end end end From 85299d0327f9639c734fcb847dd031942d13a5be Mon Sep 17 00:00:00 2001 From: Richard Eklycke Date: Fri, 7 Jan 2022 15:15:18 +0100 Subject: [PATCH 2/2] Don't spawn threads that definitely won't be needed --- lib/ceedling/par_map.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ceedling/par_map.rb b/lib/ceedling/par_map.rb index 98198a2ce..23723601e 100644 --- a/lib/ceedling/par_map.rb +++ b/lib/ceedling/par_map.rb @@ -1,9 +1,15 @@ - def par_map(n, things, &block) + if (things.length <= 1) + yield things.pop() if not things.empty? + return + end + queue = Queue.new things.each { |thing| queue << thing } - threads = (1..n).collect do + + num_threads = [n, things.length].min() + threads = (1..num_threads).collect do Thread.new do begin while true