nrules - NRules rulesRepo.Compile() 慢
问题描述
几周前,我开始与 NRules 合作。我很喜欢。但是我遇到的问题是性能......我有大约 1500 条规则(可能是很多?)动态构建,我的 rulesRepo.Compile() 需要将近 6 秒。有人有同样的问题吗?
解决方案
目的是让规则在应用程序生命周期内只编译一次(通常在应用程序启动时)。所以,性能成本是你应该只支付一次的。
另外,考虑一个自定义表达式编译器(https://github.com/NRules/NRules/wiki/Expression-Compiler),您可以在其中尝试连接https://github.com/dadhi/FastExpressionCompiler以加快编译速度
using FastExpressionCompiler;
public class FastExpressionCompiler : NRules.Extensibility.IExpressionCompiler
{
public TDelegate Compile<TDelegate>(Expression<TDelegate> expression) where TDelegate : Delegate
{
return expression.CompileFast();
}
}
并使用创建的表达式编译器进行规则编译:
var repository = new RuleRepository();
//Load rules
var compiler = new RuleCompiler();
compiler.ExpressionCompiler = new FastExpressionCompiler();
var factory = compiler.Compile(repository.GetRuleSets());
推荐阅读
- android - 如何导入 com.amazonaws.util.Throwables.failure
- r - 带有 gstat 的克里金法:带有预测的“位置处的协方差矩阵奇异”
- ios - SceneKit 中的金属着色器来勾勒对象的轮廓
- javascript - 如何设置材质 ui 时间选择器 dilog 样式
- julia - 离线使用 Julia 包管理器
- node.js - NestJS 如何将自定义 Logger 添加到自定义 ExceptionFilter
- grails - Grails 如何在不影响域对象值的情况下使用 Date.ClearTime()
- python - 在使用 iCalUID “导入”日历后,在“events.update()”功能上使用 Google Calendar API 向“与会者”发送通知时出现问题?
- android - 视图之间的相等间距,其中一些使用 ConstraintLayout 上的父级百分比
- php - DB2 选择设置参数,然后用参数值插入