Skip to content

perf: optimize rule engine with Flow-based lazy evaluation#677

Merged
tangcent merged 1 commit intomasterfrom
fix/flow-early-termination
Apr 17, 2026
Merged

perf: optimize rule engine with Flow-based lazy evaluation#677
tangcent merged 1 commit intomasterfrom
fix/flow-early-termination

Conversation

@tangcent
Copy link
Copy Markdown
Owner

  • Replace Sequence with Flow for suspend function compatibility
  • Enable early termination in aggregation modes (SINGLE, ANY, IntRuleMode)
  • Add AnyKit utilities for lenient type conversion (asInt, asBoolean)
  • Properly handle CancellationException for Flow exception transparency
  • Add comprehensive documentation to RuleModes and AnyKit

This addresses performance issues by:

  • Short-circuiting rule evaluation when terminal operators find satisfying results
  • Avoiding eager collection of all rule results when only first is needed

Closes #669

- Replace Sequence with Flow for suspend function compatibility
- Enable early termination in aggregation modes (SINGLE, ANY, IntRuleMode)
- Add AnyKit utilities for lenient type conversion (asInt, asBoolean)
- Properly handle CancellationException for Flow exception transparency
- Add comprehensive documentation to RuleModes and AnyKit

This addresses performance issues by:
- Short-circuiting rule evaluation when terminal operators find satisfying results
- Avoiding eager collection of all rule results when only first is needed

Closes #669
@github-actions github-actions Bot added the type: enhancement New feature or request label Apr 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

📦 Plugin has been packaged for this PR. You can download easy-api-3.0.5.252.0.zip from the GitHub Actions workflow run by clicking on the "Artifacts" dropdown.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 81.00000% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.910%. Comparing base (ccf01ca) to head (0111c02).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...ain/kotlin/com/itangcent/easyapi/rule/RuleModes.kt 60.000% 8 Missing and 2 partials ⚠️
...in/com/itangcent/easyapi/rule/engine/RuleEngine.kt 84.783% 4 Missing and 3 partials ⚠️
...c/main/kotlin/com/itangcent/easyapi/util/AnyKit.kt 92.308% 0 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##              master      #677       +/-   ##
===============================================
+ Coverage     53.874%   53.910%   +0.036%     
+ Complexity      2382      2375        -7     
===============================================
  Files            231       232        +1     
  Lines          13591     13582        -9     
  Branches        3070      3067        -3     
===============================================
  Hits            7322      7322               
+ Misses          4911      4910        -1     
+ Partials        1358      1350        -8     
Flag Coverage Δ
unittests 53.910% <81.000%> (+0.036%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../main/kotlin/com/itangcent/easyapi/rule/RuleKey.kt 75.000% <100.000%> (ø)
...c/main/kotlin/com/itangcent/easyapi/util/AnyKit.kt 92.308% <92.308%> (ø)
...in/com/itangcent/easyapi/rule/engine/RuleEngine.kt 83.562% <84.783%> (+13.483%) ⬆️
...ain/kotlin/com/itangcent/easyapi/rule/RuleModes.kt 71.429% <60.000%> (-16.071%) ⬇️

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ccf01ca...0111c02. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tangcent tangcent merged commit d09faa8 into master Apr 17, 2026
12 checks passed
@tangcent tangcent deleted the fix/flow-early-termination branch April 17, 2026 21:55
@github-actions github-actions Bot mentioned this pull request Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🟡 [Performance] Excessive rule evaluations per method — ~55 rule evaluations per method

1 participant