elsa-workflows / elsa-workflows/elsa-core
Issue : About the workflow running slow on the first load JSON File
- Dominant language
- C#
- Stars
- 7.9k
- Forks
- 1.5k
- Avg merge
- 15h 22m
- Merged PRs (30d)
- 114
Description
## Description
I noticed that every time I use Elsa Workflow to run a new process, there is a noticeable lag during the first execution. As shown in the example below, the first startup took 26 seconds, while the second run only took 0.6 seconds. This delay is particularly problematic in workflows that interact with hardware devices, where real-time responsiveness is critical.
Issue Summary:
**First Execution:** 26 seconds (high latency)
**Subsequent Executions:** 0.6 seconds (normal)
## Steps to Reproduce
**Workflow Structure:**
This workflow consists of a custom _CustomLog_ node and the built-in _Elsa.FlowSwitch_ node.
**CustomLog Node:**
- Input Handling: Accepts input data and transforms it into output.
- Output Routing: Passes the processed data to the Elsa.FlowSwitch node for conditional branching.
**Elsa.FlowSwitch Node:**
Condition Evaluation: Uses C# scripts to evaluate branching logic.
- Case Conditions:
- Example condition:
`Output.Get("日志记录1", "Result").ToString() == "abc" // Checks if the result of "日志记录1" equals "abc"
`
Based on this condition, the workflow routes to different branches.
**Key Technical Points:**
1. **Data Flow:** CustomLog → Elsa.FlowSwitch → Branches.
2. **Condition Script:** The C# expression dynamically evaluates runtime data to determine the execution path.
**Performance Note:** The first-time script compilation (during initial execution) may contribute to the observed 26s latency.
Here's my backend code, import the JSON configuration file, and run it
```
string workflowJsonSerializer = JsonSerializer.Serialize(workflowJsonModel, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
var workflowDefinitionModel = _activitySerializer.Deserialize(workflowJsonSerializer);
var workflow = _workflowDefinitionMapper.Map(workflowDefinitionModel);
var result = await _workflowRunner.RunAsync(workflow);
```
## Expected Behavior
I want the workflow to run for the first time as fast as it was later, say 0.6s
## Actual Behavior
But it actually took 26s for the first run and timed out badly
## Environment
- **Elsa Package Version**: V3.3.4
- **Operating System**: Windows11
- **Browser and Version**: Edge Version 134.0.3124.66 (64 bit)
## Screenshots
**FirstRunLog**

**SecondRunLog**

### **_So. Has anyone met it, can you help me, thank you very much_**
Contributor guide
Assessment
This issue has not been assessed yet.