mirror of
https://github.com/langgenius/dify-plugin-sdks.git
synced 2026-07-22 02:15:22 -04:00
[PR #128] [MERGED] fix: improve buffer handling for multimodal input #166
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/langgenius/dify-plugin-sdks/pull/128
Author: @kurokobo
Created: 5/1/2025
Status: ✅ Merged
Merged: 5/6/2025
Merged by: @Yeuoly
Base:
main← Head:massive_performance_improvement📝 Commits (5)
9d8dcabfix: improve buffer handling87c5947tests:add tests for StdioRequestReader4e1a396fix: remove useless code1e9a8eafix: handle empty lines in StdioRequestReader684d425apply ruff📊 Changes
2 files changed (+90 additions, -6 deletions)
View changed files
📝
python/dify_plugin/core/server/stdio/request_reader.py(+14 -6)➕
python/tests/servers/test_stdio.py(+76 -0)📄 Description
Summary
This (probably) resolves the issues that had been widely reported regarding high CPU usage and increased processing times with multimodal input.
There's still probably room for further speed improvements, such as by changing how JSON serialization is handled, but for now, I'm submitting this PR to address the main cause.
Related issues:
Detailed Description
There are mainly two major issues with the current implementation, both related to the
request_reader:splitthebuffercontaining all data received so farhttps://github.com/langgenius/dify-plugin-sdks/blob/a35cb4c5e6aaa3f6d419727a057b29a89300b534/python/dify_plugin/core/server/stdio/request_reader.py#L24-L32
Because of this, for example, if we attach a 5MB image, the following occurs:
splitoperation runs about 13,000 timessplit, processing is done on up to 6.7 MB of datasplitis forbufferinstead ofdataThis PR makes the following changes:
splitagainstbuffer, it first usesfindondata(up to 64 KB); if it doesn’t find a match, it does nothingsplitagainstbufferwhen ab"\n"is found, and then proceeds with the rest of the processingWith these changes, the results are:
splitruns 13,000 times on up to 6.7 MB of data each timefindruns only 100 times on up to 64 KB of data, and there is only a single 6.7 MBsplitScreenshots
Tested with attached DSL and large image on https://github.com/langgenius/dify-official-plugins/issues/648 by @Hzao (thanks for good assets👍)
Current implementation: 61s


With this PR: 12s


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.