perf: optimize IO read/write usage#8219
Conversation
WalkthroughThis PR optimizes IO read/write operations across multiple drivers by refactoring the handling of file streams. It introduces a more efficient method for caching and hashing files, reducing redundant operations and improving performance. Changes
🪧 TipsFor further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me. |
|
@petercat-assistant Re-check |
|
The pull request titled "perf: optimize IO read/write usage" is indeed present in the AlistGo/alist repository. You can view the details of this pull request here. If you have any specific questions or need further assistance regarding this pull request, feel free to ask! 🪧 TipsFor further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me. |
|
@petercat-assistant Review again |
|
The pull request titled "perf: optimize IO read/write usage" is indeed present in the AlistGo/alist repository. You can view the details of this pull request here. If you have any specific questions or need further assistance regarding this pull request, feel free to ask! 🪧 TipsFor further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me. |
|
I don't see any logic for reusing buf in this PR, such as using sync.Pool. This means that memory usage may increase significantly under high traffic compared to directly using io. Additionally, frequently allocating a large number of buf instances will lead to frequent initialization and memory allocations, as well as increased GC pressure, which introduces additional performance issues. |
|
Moreover, manually handling or reusing buf is a highly sensitive operation that may lead to data corruption, loss, or even unintended memory leaks, requiring careful testing and review. However, this PR modifies multiple drivers, covering a large codebase and a broad scope of functionality, which makes it quite risky. |
|
Optimizing I/O operations is a good approach, and I’m not saying that the changes in this PR are unacceptable. However, I hope you understand that the current implementation may not be as effective as expected, and I’m concerned that it could introduce critical bugs. |
I only modified it to not cache the upload stream to a temp file when there is a hash value, and did not use more buf |
OK. I get it. Then I will just modify the drivers I can test. |
|
我只测试了第一个提交被修改的驱动,其他没测试
开发笔记
使用bytes.Buffer作为io.CopyBuffer的写入对象,CopyBuffer会调用Buffer.ReadFrom
即使被写入的数据量与Buffer.Cap一致,Buffer也会扩大