Repository navigation
Conversation
Tunglies
marked this pull request as ready for review
November 10, 2026 11:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
XUDPConn.WriteTowraps the caller's payload withbuf.Asbefore passing it tobufio.WritePacketBuffer, which then allocates the buffer used for transmission and copies the payload into it.Allocate that transmission buffer directly with the required front and rear headroom, copy the payload, and pass it to the existing
WritePacketmethod. This removes the temporary wrapper while preserving the payload copy, packet encoding, and return behavior.The change is limited to
XUDPConn.WriteTo: one file, 10 insertions and 1 deletion.Measurements
The same method change was measured in the MetaCubeX fork through a native macOS TUN with the complete mihomo process. These numbers describe that consumer and dependency graph, not a fresh performance measurement of this upstream revision:
UDP generator → TUN → mips → mihomo → VLESS/XUDP → local server → UDP echo, with replies following the reverse path.
478af2a57c48bdb8e85f6ed93b2c3735e90ceabd, sing-vmess base9b7fdbf462a5cf6366628631ef426c1a91f5df82.WriteTopatch differs.GOMAXPROCS=4per process, one UDP socket per flow, batches of 32 requests.Absolute values are medians across four runs per variant. Changes are medians of the matched-pair ratios.
The patch saves approximately 64 bytes and one allocation per roundtrip in this workload, reducing full-process allocated bytes by about 2.5%. Paired median throughput changes ranged from −0.63% to +0.66%; these measurements do not establish a throughput, CPU, or resident-memory improvement.
All 8 million roundtrips passed sequence and payload validation. CPU profiles were collected separately from the timed runs.
Upstream validation
Based on SagerNet/sing-vmess
d800eb57f96c184426196881b76967db6f6b60e5, with its existing sing dependency unchanged.go test ./...and targeted race checks passed. Local equivalence checks compare the new method against the existing helper for first/subsequent packets, IPv4/IPv6/domain destinations, payload sizes from 0 to 16000 bytes, upstream headroom, buffer release, caller-data preservation, and write-error/short-write return behavior.