Consider the following constraint:
constraintFactory.forEach(Rule.class)
.join(Shift.class, Joiners.equal(Shift::getRuleProperty, Rule::getProperty))
.penalize(HardSoftScore.ONE_HARD)
.asConstraint("Rule violated");
Assume Shift::getRuleProperty is an expensive method to evaluate.
If a problem has no Rule instances, this constraint can never fire, since one side of the join is empty.
However, Shift::getRuleProperty is pointless re-evaluated whenever a Shift changes.
If we can detect if a root node (precompute and forEach variants) is empty, we can disable all constraints (set their weight to 0) that can never fire.
When a constraint is disabled this way, it should be reported somewhere, potentially in the logs.