Skip to content

Commit 9b25114

Browse files
committed
Merge pull request #3 from mariofusco/d1025mf
[DROOLS-1025] minor perf optimization
2 parents 18f707e + fdfd7f1 commit 9b25114

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

drools-core/src/main/java/org/drools/core/impl/KnowledgeBaseImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,11 +1410,13 @@ public void registerSegmentPrototype(LeftTupleSource tupleSource, SegmentMemory
14101410
}
14111411

14121412
public void invalidateSegmentPrototype(LeftTupleNode tupleSource, boolean ruleRemoved) {
1413-
if (ruleRemoved && tupleSource.getAssociationsSize() < 2) {
1413+
if (segmentProtos.isEmpty() || (ruleRemoved && tupleSource.getAssociationsSize() < 2)) {
14141414
return;
14151415
}
1416-
while ( tupleSource.getLeftTupleSource() != null ) {
1417-
tupleSource = tupleSource.getLeftTupleSource();
1416+
if (ruleRemoved) {
1417+
while ( tupleSource.getLeftTupleSource() != null ) {
1418+
tupleSource = tupleSource.getLeftTupleSource();
1419+
}
14181420
}
14191421
internalInvalidateSegmentPrototype(tupleSource);
14201422
}

drools-core/src/main/java/org/drools/core/phreak/AddRemoveRule.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public static void addRule(TerminalNode tn, InternalWorkingMemory[] wms, Interna
6868
// TODO Can this be made lighter, do we need to iterate up to tip.
6969
kBase.invalidateSegmentPrototype(firstSplit, false);
7070

71+
if (wms.length == 0) {
72+
return;
73+
}
74+
7175
PathEndNodes pathEndNodes = getPathEndNodes((LeftTupleSource) firstSplit, tn, null);
7276

7377
// Insert the facts for the new paths. This will iterate each new path from EndNode to the splitStart - but will not process the splitStart itself (as tha already exist).
@@ -232,6 +236,10 @@ public static void removeRule(TerminalNode tn, InternalWorkingMemory[] wms, Inte
232236
// TODO Can this be made lighter, do we need to iterate up to tip.
233237
kBase.invalidateSegmentPrototype(firstSplit, false);
234238

239+
if (wms.length == 0) {
240+
return;
241+
}
242+
235243
PathEndNodes pathEndNodes = getPathEndNodes((LeftTupleSource) firstSplit, tn, null);
236244

237245
for (InternalWorkingMemory wm : wms) {

drools-core/src/main/java/org/drools/core/phreak/SegmentUtilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ private static int updateRiaAndTerminalMemory( LeftTupleSource lt,
433433
}
434434

435435
private static int checkSegmentBoundary(LeftTupleSource lt, InternalWorkingMemory wm, int nodeTypesInSegment) {
436-
if ( !isRootNode( lt, null ) ) {
436+
if ( isRootNode( lt, null ) ) {
437437
// we are in a new child segment
438438
checkEagerSegmentCreation(lt.getLeftTupleSource(), wm, nodeTypesInSegment);
439439
nodeTypesInSegment = 0;

0 commit comments

Comments
 (0)