dify icon indicating copy to clipboard operation
dify copied to clipboard

perf: Optimize workflow execution by moving persistence logic to async thread

Open liuzhenghua opened this issue 4 months ago • 1 comments

…c thread

Checklist:

[!IMPORTANT]
Please review the checklist below before submitting your pull request.

  • [ ] Please open an issue before creating a PR or link to an existing issue
  • [x] I have performed a self-review of my own code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

Description

This PR optimizes the workflow execution process by moving the persistence logic to an asynchronous thread. This change aims to reduce execution time and improve overall performance. The new approach ensures that persistence operations no longer block the main workflow execution, allowing tasks to proceed faster while the data is saved asynchronously in the background. No changes were made to the external behavior of the workflow, ensuring backward compatibility.

Screenshots:

Before Optimization: 21519e806a4068e34fbd0107d11d8b8

After Optimization: image

The screenshots clearly illustrate the reduction in execution time after moving the persistence logic to an async thread.

Fixes

Type of Change

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] This change requires a documentation update, included: Dify Document
  • [x] Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement
  • [ ] Dependency upgrade

Testing Instructions

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [ ] Test A
  • [ ] Test B

liuzhenghua avatar Oct 17 '24 06:10 liuzhenghua