Skip to content

perf: Node unlinking in Constraint Streams when it can be determined a constraint can never fire. #1925

@Christopher-Chianelli

Description

@Christopher-Chianelli

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    process/needs triageRequires initial assessment of validity, priority etc.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions