Rule chaining in RulesEngine suffered from exponential performance degradation as reported in #471#706
Open
bhattumang7 wants to merge 2 commits intomicrosoft:mainfrom
Open
Rule chaining in RulesEngine suffered from exponential performance degradation as reported in #471#706bhattumang7 wants to merge 2 commits intomicrosoft:mainfrom
bhattumang7 wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Refactor resultList population to avoid duplication and improve performance.
|
you should be making these changes in my branch which is the only maintained fork |
asulwer
added a commit
to asulwer/RulesEngine
that referenced
this pull request
Dec 16, 2025
Rule chaining in RulesEngine suffered from exponential performance degradation as reported in microsoft#471 microsoft#706
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Performance Issue with Rule Chaining (#471)
Summary
This PR addresses the significant performance degradation in rule chaining reported in issue #471. The fix provides 8-11x performance improvements for chained rule execution by resolving two critical performance bottlenecks.
Problem Description
Rule chaining in RulesEngine suffered from exponential performance degradation as reported in #471:
The performance degraded exponentially with each additional rule in the chain, making rule chaining impractical for complex scenarios.
Root Cause Analysis
1. Inefficient Rule Compilation Caching
ExecuteActionWorkflowAsyncwas calling the individualCompileRulemethod which bypassed the compiled rules cache used byExecuteAllRulesAsync. This meant:2. Exponential Result Tree Copying
In
EvaluateRuleAction.ExecuteAndReturnResultAsync, each chained rule was copying ALL previous results:Solution
1. Implement Proper Rule Compilation Caching
File:
src/RulesEngine/RulesEngine.csExecuteActionWorkflowAsyncto use newGetCompiledRulemethodGetCompiledRuleleverages the same caching mechanism asExecuteAllRulesAsync2. Optimize Result Tree Aggregation
File:
src/RulesEngine/Actions/EvaluateRuleAction.csExecuteAndReturnResultAsyncto avoid exponential copyingTesting
Performance Validation
Created comprehensive performance tests (
PerformanceTest/Program.cs) that reproduce the original issue scenarios:Regression Testing
All existing unit tests pass, ensuring no functionality regression:
Impact
This fix transforms rule chaining from an impractical feature with exponential performance degradation into a viable solution for complex rule scenarios. Users can now:
Related Issues
Type of Change