From e4f8e653c100781e42af779fd3cbe14d6ca03dac Mon Sep 17 00:00:00 2001 From: shaoxiaoxu Date: Fri, 21 Jun 2024 09:56:22 +0800 Subject: [PATCH] perf: Optimize the processing speed of EvaluateRuleAction --- 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; }