Drools 中原始数据类型与非原始数据类型的性能

Performance of primitive vs. non-primitive data types in Drools

我想知道与 Drools 中的非原始数据类型相比,使用原始数据对性能和内存使用有何影响。

documentation中表示:

8.8.6. A Note on Auto-boxing and Primitive Types Drools attempts to preserve numbers in their primitive or object wrapper form, so a variable bound to an int primitive when used in a code block or expression will no longer need manual unboxing; unlike Drools 3.0 where all primitives were autoboxed, requiring manual unboxing. A variable bound to an object wrapper will remain as an object; the existing JDK 1.5 and JDK 5 rules to handle auto-boxing and unboxing apply in this case. When evaluating field constraints, the system attempts to coerce one of the values into a comparable format; so a primitive is comparable to an object wrapper.

基本上,在我的规则中,我有这样的条件:

$someObj : SomeObj( someIntOrIntegerField > 15 )

累积如下:

$total : Double() from accumulate (
                 SomeObj(
                    $someIntOrIntegerField : someIntOrIntegerField) over window:time( 1h ),
                 sum( $someIntOrIntegerField ) )

我的理解是 Drools 将强制转换委托给 JVM 而没有做任何事情 boxing/unboxing。这是真的?当我在几毫秒内与时间赛跑时,我想知道哪个会更快:

int someIntOrIntegerField;

Integer someIntOrIntegerField;

请注意,我的问题是关于在 Drools 中是否存在我不知道的 boxing/unboxing,以及原语或 Objects 是否更快更高效(就内存而言) ,再次仅限于 Drools。否则,一般有一个很好的答案 Java 范围:https://softwareengineering.stackexchange.com/a/203971

你的问题中需要回答的部分是:

What I understand is that Drools delegates coercion to JVM and does not do any boxing/unboxing. Is this true?

不,这不是真的。 JVM 不执行自动装箱/拆箱转换。是(源 -> 字节码)编译器负责将对(例如)Integer.valueOf(int)Integer.intValue() 的调用插入到字节码中的适当位置。您可以使用 javap 检查“.class”文件来验证这一点。

对于 Drools,编译器生成“.class”文件,这些文件在字节码中包含任何必要的自动装箱/拆箱。我认为您引用的文档实际上意味着 Drools 编译器的自动装箱/拆箱策略已经改变......自 Drools 3.0