elsa-workflows / elsa-workflows/elsa-core

[PERF] Optimize WorkflowDefinitionActivity Loading with Caching

Open
#5,249 0 comments 0 reactions 0 assignees View on GitHub
performance triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

### Problem

Currently, when handling workflows that involve `WorkflowDefinitionActivity`, which links to other workflows, 1 to 3 SQL queries are executed to fetch the linked workflow definition per `WorkflowDefinitionActivity` instance. This repetitive querying occurs regardless of whether the same workflow definition was previously loaded, leading to inefficiencies. This issue is exacerbated in complex workflow graphs with deep nesting and multiple instances of `WorkflowDefinitionActivity`, significantly impacting both application startup time and workflow execution performance when caching is not enabled.

### Proposed Solution

To address this performance bottleneck, it is proposed to implement a caching mechanism. By introducing a dictionary to cache previously loaded workflow definitions, we can avoid redundant SQL queries during the initialization of the workflow graph. This dictionary would store workflow definitions that have already been retrieved, thereby reducing the number of database hits.

### Expected Impact

- **Reduced SQL Queries:** Minimize the database operations required during workflow initialization.
- **Enhanced Performance:** Improve the startup and execution throughput of applications utilizing complex workflows.
- **Scalability:** Better handle larger and more complex workflow graphs without a corresponding increase in resource consumption.

### Notes

- This optimization should work separate from the existing caching feature, which uses a "real" cache.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.