Commit 769d4a7
committed
http-connect: reduce memory allocations
Introduce a `sync.Pool` to reuse read buffers in the `ServeHTTP` handler
for the http-connect mode.
Previously, a new 32KB buffer was allocated for every hijacked
connection, causing high GC pressure in high-throughput scenarios. By
pooling and reusing these buffers, we significantly reduce the number of
memory allocations, which improves CPU usage and lowers request latency
by decreasing the impact of garbage collection.
Signed-off-by: Imran Pochi <[email protected]>1 parent 7c8afba commit 769d4a7
1 file changed
+24
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
32 | 48 | | |
33 | 49 | | |
34 | 50 | | |
| |||
176 | 192 | | |
177 | 193 | | |
178 | 194 | | |
179 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
180 | 203 | | |
181 | 204 | | |
182 | 205 | | |
| |||
0 commit comments