Skip to content

XHTTP transport: Replace io.ReadAll with io.ReadFull in ServeHTTP; Simplify uploadWriter.Write#5801

Closed
ozeranskii wants to merge 2 commits intoXTLS:mainfrom
ozeranskii:optimize/xhttp-memory-reduction
Closed

XHTTP transport: Replace io.ReadAll with io.ReadFull in ServeHTTP; Simplify uploadWriter.Write#5801
ozeranskii wants to merge 2 commits intoXTLS:mainfrom
ozeranskii:optimize/xhttp-memory-reduction

Conversation

@ozeranskii
Copy link
Copy Markdown
Contributor

Summary

  • hub.go: Replace io.ReadAll(io.LimitReader(...)) with single exact-size allocation + io.ReadFull, avoiding grow-and-copy pattern that causes unnecessary heap allocations on every POST request
  • hub.go: Add fast-path to skip slices.Concat when only one payload source has data (the common case for packet-up mode)
  • dialer.go: Simplify uploadWriter.Write - replace MultiBufferContainer wrapper with direct buf.New() per chunk, remove dead commented-out code

Benchmark (5MB transfer, packet-up, HTTP/1.1)

                          main            optimized       delta
MB_alloc (TotalAlloc)     31.6 MB         21.9 MB         -31%
allocs/op                 5,303           4,716           -11%
ns/op                     218M            227M            ~0%

Server-side io.ReadFull with exact-size pre-allocation eliminates io.ReadAll's repeated grow-and-copy on each POST body read.

Relates to #5344, #5797

Replace io.ReadAll grow-and-copy with exact-size io.ReadFull allocations on both client (PostPacket) and server (ServeHTTP) paths. Skip slices.Concat when only one payload source has data. Bound concurrent upload goroutines with a semaphore to limit peak memory. Clean up dead XmuxManager entries from globalDialerMap to prevent unbounded map growth. Simplify uploadWriter removing MultiBufferContainer overhead. Fix double-free in uploadWriter on pipe write error.
@Fangliding
Copy link
Copy Markdown
Member

Fangliding commented Mar 13, 2026

别再开这些AI PR了 我说了我会处理的

@Fangliding Fangliding closed this Mar 13, 2026
@ozeranskii
Copy link
Copy Markdown
Contributor Author

ozeranskii commented Mar 13, 2026

@Fangliding Okay, whatever you say. I didn't know this repository wasn't about OSS. I never saw any mention of it being a solo project. No problem.

@ozeranskii ozeranskii deleted the optimize/xhttp-memory-reduction branch March 13, 2026 19:33
RPRX pushed a commit that referenced this pull request Mar 21, 2026
#5801
#5808

---------

Co-authored-by: Sergei Ozeranskii <sergey.ozeranskiy@gmail.com>
Co-authored-by: rufsieus <rufsieus@gmail.com>
@RPRX
Copy link
Copy Markdown
Member

RPRX commented Mar 21, 2026

c1b67a9 加了 co-author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants