From be353fc9d45bc92c4612788e708d71bae5fc5160 Mon Sep 17 00:00:00 2001 From: Chunel Date: Fri, 31 Jul 2026 23:39:35 +0800 Subject: [PATCH 1/2] [chron] optimise isFastFinished checker --- .../_GEngine/GDynamicEngine/GDynamicEngine.cpp | 11 +++-------- test/Performance/test-performance-04.cpp | 1 + 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/GraphCtrl/GraphElement/_GEngine/GDynamicEngine/GDynamicEngine.cpp b/src/GraphCtrl/GraphElement/_GEngine/GDynamicEngine/GDynamicEngine.cpp index dd31bf4d..29aa8c55 100644 --- a/src/GraphCtrl/GraphElement/_GEngine/GDynamicEngine/GDynamicEngine.cpp +++ b/src/GraphCtrl/GraphElement/_GEngine/GDynamicEngine/GDynamicEngine.cpp @@ -306,17 +306,12 @@ CVoid GDynamicEngine::prepareRun() { template CBool GDynamicEngine::isFastFinished(Pred&& check) { - CBool result = false; - const auto epoch = thread_pool_->getConfig().pipeline_wait_busy_epoch_; - for (auto i = 0; i < epoch; i++) { - if (check()) { - result = true; - break; - } + auto epoch = thread_pool_->getConfig().pipeline_wait_busy_epoch_; + while (epoch-- > 0 && !check()) { CGRAPH_YIELD(); } - return result; + return epoch >= 0; } CGRAPH_NAMESPACE_END diff --git a/test/Performance/test-performance-04.cpp b/test/Performance/test-performance-04.cpp index a84924e4..cb173378 100644 --- a/test/Performance/test-performance-04.cpp +++ b/test/Performance/test-performance-04.cpp @@ -24,6 +24,7 @@ void test_performance_04() { config.primary_thread_busy_epoch_ = 500; config.primary_thread_empty_interval_ = 0; config.deliver_running_primary_thread_enable_ = true; + config.pipeline_wait_busy_epoch_ = 100; pipeline->setUniqueThreadPoolConfig(config); // 实现一个全连接 From 4950664430b3f1cce83be2a33cdaa1fed47e0fca Mon Sep 17 00:00:00 2001 From: Chunel Date: Fri, 31 Jul 2026 23:48:56 +0800 Subject: [PATCH 2/2] [chron] add some const for var and func --- src/GraphCtrl/GraphElement/GElement.cpp | 2 +- src/GraphCtrl/GraphElement/GElement.h | 4 ++-- src/GraphCtrl/GraphElement/GElementManager.cpp | 2 +- src/GraphCtrl/GraphElement/GElementManager.h | 3 +-- src/GraphCtrl/GraphElement/GGroup/GCluster/GCluster.cpp | 2 +- .../GraphElement/GGroup/GCondition/GCondition.cpp | 2 +- .../GraphElement/GGroup/GCondition/GConditionDefine.h | 1 - src/GraphCtrl/GraphElement/GGroup/GGroup.cpp | 8 ++++---- src/GraphCtrl/GraphElement/GGroup/GGroup.h | 2 +- src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.cpp | 2 +- src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.h | 2 +- src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.cpp | 2 +- src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.h | 2 +- src/GraphCtrl/GraphElement/GNode/GNode.cpp | 2 +- src/GraphCtrl/GraphElement/GNode/GNode.h | 2 +- 15 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/GraphCtrl/GraphElement/GElement.cpp b/src/GraphCtrl/GraphElement/GElement.cpp index 9bc8053d..58a9fa1b 100644 --- a/src/GraphCtrl/GraphElement/GElement.cpp +++ b/src/GraphCtrl/GraphElement/GElement.cpp @@ -348,7 +348,7 @@ CStatus GElement::crashed(const CException& ex) const { } -CIndex GElement::getThreadIndex() { +CIndex GElement::getThreadIndex() const { CGRAPH_THROW_EXCEPTION_BY_CONDITION((nullptr == thread_pool_), \ this->getName() + " getThreadIndex with no thread pool") // 理论不可能出现的情况 diff --git a/src/GraphCtrl/GraphElement/GElement.h b/src/GraphCtrl/GraphElement/GElement.h index 1741d1a2..70e669c9 100644 --- a/src/GraphCtrl/GraphElement/GElement.h +++ b/src/GraphCtrl/GraphElement/GElement.h @@ -102,7 +102,7 @@ class GElement : public GElementObject, /** * 设定绑定的线程id - * @param index,需要绑定的 thread id 信息 + * @param index 需要绑定的 thread id 信息 * @return * @notice 本接口仅保证绑定线程优先调度,但不保证最终一定在绑定线程上执行。若不了解调度机制,不建议使用本接口,否则可能导致运行时阻塞。 */ @@ -242,7 +242,7 @@ class GElement : public GElementObject, * @return * @notice 启动线程返回-1(CGRAPH_MAIN_THREAD_ID),辅助线程返回-2(CGRAPH_SECONDARY_THREAD_COMMON_ID),主线程返回 线程index */ - CIndex getThreadIndex(); + CIndex getThreadIndex() const; /** * 判断当前是否超时 diff --git a/src/GraphCtrl/GraphElement/GElementManager.cpp b/src/GraphCtrl/GraphElement/GElementManager.cpp index 34a49bbb..71646849 100644 --- a/src/GraphCtrl/GraphElement/GElementManager.cpp +++ b/src/GraphCtrl/GraphElement/GElementManager.cpp @@ -129,7 +129,7 @@ GElementManagerPtr GElementManager::setThreadPool(UThreadPoolPtr ptr) { } -CSize GElementManager::calcMaxParaSize() { +CSize GElementManager::calcMaxParaSize() const { CGRAPH_THROW_EXCEPTION_BY_CONDITION(!GMaxParaOptimizer::match(manager_elements_), "cannot calculate max parallel size within groups") return GMaxParaOptimizer::getMaxParaSize(manager_elements_); diff --git a/src/GraphCtrl/GraphElement/GElementManager.h b/src/GraphCtrl/GraphElement/GElementManager.h index 1ded97a1..57da8e3d 100644 --- a/src/GraphCtrl/GraphElement/GElementManager.h +++ b/src/GraphCtrl/GraphElement/GElementManager.h @@ -61,7 +61,6 @@ class GElementManager : public GElementObject, /** * 构造执行引擎 - * @param strategy * @return */ CStatus initEngine(); @@ -77,7 +76,7 @@ class GElementManager : public GElementObject, * 获取最大的并发数 * @return */ - CSize calcMaxParaSize(); + CSize calcMaxParaSize() const; /** * 查看是否可以串行执行 diff --git a/src/GraphCtrl/GraphElement/GGroup/GCluster/GCluster.cpp b/src/GraphCtrl/GraphElement/GGroup/GCluster/GCluster.cpp index caf10988..db5a7f18 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GCluster/GCluster.cpp +++ b/src/GraphCtrl/GraphElement/GGroup/GCluster/GCluster.cpp @@ -18,7 +18,7 @@ GCluster::GCluster() { CStatus GCluster::run() { CGRAPH_FUNCTION_BEGIN - for (GElementPtr element : this->children_) { + for (const GElementPtr element : this->children_) { status = element->fatProcessor(CFunctionType::RUN); CGRAPH_FUNCTION_CHECK_STATUS } diff --git a/src/GraphCtrl/GraphElement/GGroup/GCondition/GCondition.cpp b/src/GraphCtrl/GraphElement/GGroup/GCondition/GCondition.cpp index 3615429e..d1a87dc7 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GCondition/GCondition.cpp +++ b/src/GraphCtrl/GraphElement/GGroup/GCondition/GCondition.cpp @@ -19,7 +19,7 @@ GCondition::GCondition() { CStatus GCondition::run() { CGRAPH_FUNCTION_BEGIN - CIndex index = this->choose(); + const CIndex index = this->choose(); if (internal::CGRAPH_CONDITION_LAST_INDEX == index && !this->children_.empty()) { // 如果返回-1,则直接执行最后一个条件(模仿default功能) diff --git a/src/GraphCtrl/GraphElement/GGroup/GCondition/GConditionDefine.h b/src/GraphCtrl/GraphElement/GGroup/GCondition/GConditionDefine.h index 7c02da60..53f4f2b7 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GCondition/GConditionDefine.h +++ b/src/GraphCtrl/GraphElement/GGroup/GCondition/GConditionDefine.h @@ -9,7 +9,6 @@ #ifndef CGRAPH_GCONDITIONDEFINE_H #define CGRAPH_GCONDITIONDEFINE_H -#include "../GGroupDefine.h" CGRAPH_NAMESPACE_BEGIN diff --git a/src/GraphCtrl/GraphElement/GGroup/GGroup.cpp b/src/GraphCtrl/GraphElement/GGroup/GGroup.cpp index a4deac31..de531110 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GGroup.cpp +++ b/src/GraphCtrl/GraphElement/GGroup/GGroup.cpp @@ -17,7 +17,7 @@ GGroup::GGroup() { CStatus GGroup::init() { CGRAPH_FUNCTION_BEGIN - for (GElementPtr element : children_) { + for (const GElementPtr element : children_) { CGRAPH_ASSERT_NOT_NULL(element) status += element->fatProcessor(CFunctionType::INIT); } @@ -31,7 +31,7 @@ CStatus GGroup::init() { CStatus GGroup::destroy() { CGRAPH_FUNCTION_BEGIN - for (GElementPtr element : children_) { + for (const GElementPtr element : children_) { CGRAPH_ASSERT_NOT_NULL(element) status += element->fatProcessor(CFunctionType::DESTROY); } @@ -81,7 +81,7 @@ CVoid GGroup::dumpGroupLabelBegin(std::ostream& oss) { } -CVoid GGroup::dumpGroupLabelEnd(std::ostream& oss) { +CVoid GGroup::dumpGroupLabelEnd(std::ostream& oss) const { (void)(this); oss << "}\n"; } @@ -93,7 +93,7 @@ CBool GGroup::isSerializable() const { * 但是在 region和 multiCondition中,有针对性的判断 */ return std::all_of(children_.begin(), children_.end(), - [](GElementPtr element) { + [](const GElementPtr element) { return element->isSerializable(); }); } diff --git a/src/GraphCtrl/GraphElement/GGroup/GGroup.h b/src/GraphCtrl/GraphElement/GGroup/GGroup.h index 6a1f50cd..6cba84f4 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GGroup.h +++ b/src/GraphCtrl/GraphElement/GGroup/GGroup.h @@ -58,7 +58,7 @@ class GGroup : public GElement { * @param oss * @return */ - CVoid dumpGroupLabelEnd(std::ostream& oss); + CVoid dumpGroupLabelEnd(std::ostream& oss) const; /** * 判断两个element,是否相互独立 diff --git a/src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.cpp b/src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.cpp index f10f3853..523d23ae 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.cpp +++ b/src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.cpp @@ -76,7 +76,7 @@ GElementPtr GMutable::setThreadPoolEx(UThreadPoolPtr ptr) { } -CVoid GMutable::setup() { +CVoid GMutable::setup() const { for (auto* element : children_) { element->run_before_.clear(); element->dependence_.clear(); diff --git a/src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.h b/src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.h index ed9428e9..719a3424 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.h +++ b/src/GraphCtrl/GraphElement/GGroup/GMutable/GMutable.h @@ -40,7 +40,7 @@ class GMutable : public GGroup { * 将数据进行恢复 * @return */ - CVoid setup(); + CVoid setup() const; GElementPtr setThreadPoolEx(UThreadPoolPtr ptr) final; diff --git a/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.cpp b/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.cpp index 32a4a306..cb43561c 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.cpp +++ b/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.cpp @@ -114,7 +114,7 @@ CBool GRegion::isSeparate(GElementCPtr a, GElementCPtr b) const { } -CSize GRegion::trim() { +CSize GRegion::trim() const { CGRAPH_ASSERT_INIT_THROW_ERROR(false) CSize result = 0; if (manager_) { diff --git a/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.h b/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.h index 8d55e97d..f3ce2730 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.h +++ b/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.h @@ -28,7 +28,7 @@ class GRegion : public GGroup { * 修剪冗余的连边信息 * @return */ - CSize trim(); + CSize trim() const; protected: explicit GRegion(); diff --git a/src/GraphCtrl/GraphElement/GNode/GNode.cpp b/src/GraphCtrl/GraphElement/GNode/GNode.cpp index 5a798804..46449f1f 100644 --- a/src/GraphCtrl/GraphElement/GNode/GNode.cpp +++ b/src/GraphCtrl/GraphElement/GNode/GNode.cpp @@ -22,7 +22,7 @@ GNodePtr GNode::setType(const GNodeType& type) { } -CStatus GNode::spawn(const UTaskGroup& tasks, CMSec ttl) { +CStatus GNode::spawn(const UTaskGroup& tasks, const CMSec ttl) const { CGRAPH_FUNCTION_BEGIN CGRAPH_ASSERT_INIT(true) CGRAPH_ASSERT_NOT_NULL(thread_pool_) diff --git a/src/GraphCtrl/GraphElement/GNode/GNode.h b/src/GraphCtrl/GraphElement/GNode/GNode.h index 1ba38043..fe9aee17 100644 --- a/src/GraphCtrl/GraphElement/GNode/GNode.h +++ b/src/GraphCtrl/GraphElement/GNode/GNode.h @@ -33,7 +33,7 @@ class GNode : public GElement { * @param ttl * @return */ - CStatus spawn(const UTaskGroup& tasks, CMSec ttl = CGRAPH_MAX_BLOCK_TTL); + CStatus spawn(const UTaskGroup& tasks, CMSec ttl = CGRAPH_MAX_BLOCK_TTL) const; private: GNodeType node_type_ { GNodeType::BASIC }; // 节点类型