mirror of
https://github.com/langgenius/dify-plugin-sdks.git
synced 2026-07-22 02:15:22 -04:00
[PR #201] [MERGED] fix: resolve 100% CPU usage in stdio buffer by replacing O(n²) Byte concatenation with BytesIO #217
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/201
Author: @biubiuqiu
Created: 9/4/2025
Status: ✅ Merged
Merged: 9/8/2025
Merged by: @Yeuoly
Base:
main← Head:fix/performance-stdio-buffer📝 Commits (2)
9203dedfix: improve stream reading and buffering logic63c63b6fix: Re-add accidentally deleted line📊 Changes
1 file changed (+21 additions, -9 deletions)
View changed files
📝
python/dify_plugin/core/server/stdio/request_reader.py(+21 -9)📄 Description
Description
Problem
The StdioRequestReader caused 100% CPU usage due to a critical O(n²) performance bottleneck in buffer management. The inefficient buffer += data operations were consuming massive CPU resources through repeated memory allocations and copies.
Issues identified:
Solution
Replaced inefficient bytes concatenation with BytesIO for optimal buffer management:
Performance Impact
For processing 1MB of data in 64KB chunks:
Root Cause
Python's bytes concatenation with += operator is inherently expensive for growing buffers. Each operation:
This results in exponential CPU consumption as buffer size grows.
Changes Made
Testing
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.