Performance Bottleneck on PackageClassLoader

11 views
Skip to first unread message

Sushan Baskota

unread,
Oct 10, 2025, 4:22:42 PM (8 days ago) Oct 10
to Drools Usage

Dear community/drools team,

In my current project, compiled Collection<KiePackages> are stored as byte arrays and deserialized at runtime to convert them into KieBase objects. These KieBase instances are cached in-memory, and stateless KieSessions are created dynamically from them.

However, I’ve observed that the first execution of rules is significantly slow due to class loading overhead, specifically caused by a lock on PackageClassLoader. This has become a major bottleneck, especially since I’m dealing with thousands of unique rules that utilize similar fact objects. Each execution triggers class loading for the same set of classes, which is inefficient.

Approaches Tried So Far:
  • Pre-warming rules at startup: This helps reduce runtime latency but introduces a noticeable startup delay, which is problematic.
  • Custom class loader implementation: Attempted to optimize class loading, but it doesn’t fully cover all dynamically generated classes.
Request for Suggestions:

Is there a recommended approach to avoid or minimize class loading during runtime in this scenario? Any strategies or best practices to preload or reuse class definitions efficiently would be greatly appreciated.


Sample code from my project:

On rule execution

// deserialized Kiepackages to get Kiebase
InternalKnowledgeBase kiebase =  KnowledgeBaseFactory.newKnowledgeBase();

KieBasePackages kieBasePackages =(KieBasePackages) ois.readObject();
           
 kiebase.addPackages(kieBasePackages.packages());

// get keisession from kiebase
StatelessKieSession statelessKieSession = kieBase.newStatelessKieSession();

//fire rule
 statelessKieSession.execute(facts);

Thanks,
Sushan.


Alex Porcelli

unread,
Oct 10, 2025, 8:30:23 PM (8 days ago) Oct 10
to drools...@googlegroups.com
What version are you using?

Sounds like you could benefit from a more recent version with an
executable model.
> --
> You received this message because you are subscribed to the Google Groups "Drools Usage" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/drools-usage/f02086a6-4991-42e2-b167-cf7b26bc4773n%40googlegroups.com.

Sushan Baskota

unread,
Oct 11, 2025, 10:52:18 AM (7 days ago) Oct 11
to drools...@googlegroups.com
I am using version 8+. And I am trying to find an option on existing design. 
Executable model needs significant redesign on the architecture so I am keeping that option aside for now.

Thanks

Alex Porcelli

unread,
Oct 11, 2025, 11:21:03 AM (7 days ago) Oct 11
to drools...@googlegroups.com
I strongly recommend upgrading to 10.1.x. Version 8.x is not only
outdated but also no longer maintained, which puts you in a difficult
position moving forward.
> To view this discussion visit https://groups.google.com/d/msgid/drools-usage/CAM4EB%3Ds_epF8nqy%3DXP4291qQtvPe7A1Rdf4oN8LFyTZU%2BbrsFA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages