Better to add multiple facts using single inserts(...) or using a List?
12:36 04 Nov 2025

We have the following situation when setting up a Drools rule execution:

List persons = List.of(person1, person2, ...); // in essence, it's just a List of something
KieSession kieSession = kieContainer.newKieSession();
kieSession.insert(persons);
kieSession.fireAllRules();

Is it the right/correct/best approach to add all persons using a List? Or should it be done the following way?

Person person1 = Person.builder().name("Fred").build();
Person person2 = Person.builder().name("Mr. Naughty").build();

List persons = List.of(person1, person2, ...); // in essence, it's just a List of something
KieSession kieSession = kieContainer.newKieSession();

for (Person p : persons) {
  kieSession.insert(p);
}
kieSession.fireAllRules();

i.e. adding the fact one by one? The documentation/samples always just give a couple facts, which are added one by one, I've never seen a sample using the List. But the system I'm talking about is using the List approach and it works. It's just said to be slow. So I'm wondering if the Rete algorithm just doesn't analyze the List's contents, but adds the List itself as a fact.

On the other hand: if the facts (here: Persons) get added in a singular way, is it still possible to perform a count on amount of Persons?

drools