refactor(buffer): Optimizes TCP and HTTP streaming request processing using a buffer pool.

Replaces the fixed-size buffers in `FrameHandler` and `Handler` with dynamic buffers obtained from the buffer pool,

to reduce memory allocation and improve performance. Also updates the logo path in the README to match the new resource directory structure.
This commit is contained in:
Gouryella
2025-12-08 12:53:56 +08:00
parent 7283180e6a
commit 1a5ffce15c
5 changed files with 8 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
<p align="center">
<img src="images/logo.png" alt="Drip Logo" width="200" />
<img src="assets/logo.png" alt="Drip Logo" width="200" />
</p>
<h1 align="center">Drip</h1>

View File

@@ -1,5 +1,5 @@
<p align="center">
<img src="images/logo.png" alt="Drip Logo" width="200" />
<img src="assets/logo.png" alt="Drip Logo" width="200" />
</p>
<h1 align="center">Drip</h1>

View File

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View File

@@ -354,7 +354,9 @@ func (h *FrameHandler) adaptiveHTTPResponse(streamID, requestID string, resp *ht
// Buffer for initial read
buffer := make([]byte, 0, threshold)
tempBuf := make([]byte, 32*1024) // 32KB read chunks
tempBufPtr := h.bufferPool.Get(pool.SizeMedium)
defer h.bufferPool.Put(tempBufPtr)
tempBuf := (*tempBufPtr)[:pool.SizeMedium]
var totalRead int64
var hitThreshold bool

View File

@@ -312,7 +312,9 @@ func (h *Handler) streamLargeRequest(w http.ResponseWriter, r *http.Request, tra
}
}
buffer := make([]byte, 32*1024)
streamBufPtr := h.bufferPool.GetMedium()
defer h.bufferPool.PutMedium(streamBufPtr)
buffer := (*streamBufPtr)[:pool.MediumBufferSize]
for {
n, readErr := r.Body.Read(buffer)
if n > 0 {