Repository navigation
Performance: Repeated ServiceLoader scanning without caching #1611
Description
Activity
- added a commit that references this issue
on Aug 8, 2026 There should not be multiple WorkflowApplication objects within the same JVM
If you follow that policy (which must be followed), not caching the service loader in WorkflowApplication should not be an issue (so there is no performance improvement in caching services that are only processed during WorkflowApplicaiton.build(), but there is an impact in memory because those collection will remain associated to the application, so, on summary, do NOT create several WorkflowApplication object in your JVM and do not create cached collection for service loaders used in Workflowapplication)
For other usages of uncached service loaders outside workflow application (which I think are only Run and Emit cases) please feel free to open PR.- addedjavaPull requests that update java codePull requests that update java code
on Aug 11, 2026 I did further analysis,
WorkflowApplication, as already discussed, should not be cached (one of the only valid reasons to load different Workflowapplication withint the same JVM is actually to rescan application service loaders)
EmitExecutor is already "cached", so it only loaded once, no cache necessary (yes this actually creates an assimetry with WorkflwApplication ones, but it can be justified by the nature of the decorator)
RunScriptExecutor, RunTaskExecutor and HttpExecutor ones are only loaded once per workflow definition (not per execution, thats a critical point) containing a script, but they are good candidates for cachig (caching makes a lot of sense)
Im opening a PR for those three.- added 2 commits that reference this issue
on Aug 11, 2026 - added 2 commits that reference this issue
on Aug 11, 2026 - added a commit that references this issue
on Aug 12, 2026
Problem
ServiceLoader instances are being loaded and scanned repeatedly during
WorkflowApplication.build()and other initialization paths without caching the results. ServiceLoader scanning is expensive because it:This becomes a bottleneck when:
WorkflowApplicationinstances are createdCurrent Issues
WorkflowApplication.java (lines 472, 482)
Called during every
build()invocation.RunTaskExecutor.java (line 36)
Then rescanned via
runnables.stream()with.sorted()on every task execution.EmitExecutor.java (line 48)
RunScriptExecutorBuilder.java (line 57)
ServiceLoader lookup happens per task without caching results by language.
DefaultTaskExecutorFactory.java (line 50)
Good example of caching (at initialization), but other locations don't follow this pattern.
Impact
WorkflowApplicationcreationSuggested Fix
WorkflowApplicationlevelExample Solution (Conceptual)
Then pass this through to executors that need service lookups.