From 1eb253f8de4e112272927ce66d41ad687833d1ab Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Thu, 6 Feb 2025 12:02:56 +1100 Subject: [PATCH 1/2] Cache pool information on reactions to avoid finding it each time --- src/threading/Reaction.hpp | 7 +++++++ src/threading/scheduler/Scheduler.cpp | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/threading/Reaction.hpp b/src/threading/Reaction.hpp index acc8439f..60964a8f 100644 --- a/src/threading/Reaction.hpp +++ b/src/threading/Reaction.hpp @@ -44,6 +44,9 @@ namespace threading { // Forward declare class ReactionTask; struct ReactionIdentifiers; + namespace scheduler { + class Scheduler; + } /** * This class holds the definition of a Reaction. @@ -131,6 +134,10 @@ namespace threading { /// The callback generator function (creates databound callbacks) TaskGenerator generator; + + /// Cached data for this reaction added by the scheduler + std::shared_ptr scheduler_data; + friend class scheduler::Scheduler; /// Let the scheduler mess with reaction objects }; } // namespace threading diff --git a/src/threading/scheduler/Scheduler.cpp b/src/threading/scheduler/Scheduler.cpp index 23ef8aa5..422001ce 100644 --- a/src/threading/scheduler/Scheduler.cpp +++ b/src/threading/scheduler/Scheduler.cpp @@ -188,8 +188,23 @@ namespace threading { return; } - // Get the pool and locks for the group group - auto pool = get_pool(task->pool_descriptor); + // If we have run this task before, we know which pool it should be submitted to and cached it + // This avoids every single submit having to lock a mutex to find the pool + std::shared_ptr pool; + if (task->parent) { + if (task->parent->scheduler_data) { + pool = std::static_pointer_cast(task->parent->scheduler_data); + } + else { + pool = get_pool(task->pool_descriptor); + task->parent->scheduler_data = pool; + } + } + else { + pool = get_pool(task->pool_descriptor); + } + + // Get any locks that are required for this task auto group_lock = get_groups_lock(task->id, task->priority, pool, task->group_descriptors); // If this task should run immediately and not limited by the group lock From fd22672d57613b11348d699d8e8501cbb64355a7 Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Thu, 6 Feb 2025 12:07:56 +1100 Subject: [PATCH 2/2] clang-tidy --- src/threading/Reaction.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/threading/Reaction.hpp b/src/threading/Reaction.hpp index 60964a8f..6372d101 100644 --- a/src/threading/Reaction.hpp +++ b/src/threading/Reaction.hpp @@ -46,7 +46,7 @@ namespace threading { struct ReactionIdentifiers; namespace scheduler { class Scheduler; - } + } // namespace scheduler /** * This class holds the definition of a Reaction.