From a9c3c6eefa87aa198306207504dfc4821daee38c Mon Sep 17 00:00:00 2001 From: Aprite Date: Fri, 23 Aug 2024 08:11:47 +0800 Subject: [PATCH] perf: Optimize the processing speed of EvaluateRuleAction (#612) Co-authored-by: shaoxiaoxu Co-authored-by: YogeshPraj --- src/RulesEngine/Actions/ActionContext.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/RulesEngine/Actions/ActionContext.cs b/src/RulesEngine/Actions/ActionContext.cs index af66cdc8..1c86778d 100644 --- a/src/RulesEngine/Actions/ActionContext.cs +++ b/src/RulesEngine/Actions/ActionContext.cs @@ -45,6 +45,13 @@ public bool TryGetContext(string name,out T output) { try { + //key not found return + //Returning a KeyNotFoundException has a significant impact on performance. + if (!_context.ContainsKey(name)) + { + output = default(T); + return false; + } output = GetContext(name); return true; }