Repository navigation
Avoid per-datagram SOCKS5 reply address allocations - #132
Merged
Merged
Conversation
andre487
force-pushed
the
optimize-socks5-udp
branch
from
October 27, 2026 15:44
ea5f9ad to
9498ef5
Compare
andre487
force-pushed
the
optimize-socks5-udp
branch
from
October 27, 2026 15:51
9498ef5 to
7720c0a
Compare
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.
Pull request stack
GitHub stack #135.
Merge order: #131 → #132 → #133.
Base: #131. Each PR contains only its own change relative to its parent. After merging lower layers, use
gh stack syncto update local tracking and restack the remaining branches.SOCKS5 UDP receive currently allocates address strings on every IP reply, and constructs two UDPAddr objects for each domain-target reply. Match validated wire addresses directly when their types match and read the validated numeric reply's port without constructing UDPAddr objects. Retain textual matching for different address types, including equivalent IPv4/IPv4-mapped IPv6 replies.
The source-validation policy, concurrency limits and disabled-mode dispatch path are unchanged. This reduces allocation pressure in SOCKS5 with strict validation either enabled or disabled.
Validation: all 331 native tests passed with the race detector. Add reply-policy cases for IPv4/IPv6, both mapped directions, incorrect IP/port and malformed domain-route headers. Tighten the existing steady-state IPv4 allocation budget to zero and extend the receive benchmark to cover all reply types.
Host microbenchmarks on Apple M4 Pro, GOMAXPROCS=1, ten 200 ms samples per scenario, 1200-byte payloads; before/after use identical extended benchmark definitions. CPU/allocation profiles identify address formatting as the original allocation source; after optimization payload copying dominates the receive CPU profile.
The first four improvements are statistically significant in benchstat (p < 0.001, n=10). The mapped path retains its allocation-producing compatibility fallback. These are in-memory Go receive costs, not measured VPN throughput or Android JNI/owner-lookup overhead. Full core samples still show zero allocations for guarded UDP reads; no security synchronization is removed to improve synthetic timings.
Benchmark runner and analysis instructions are in the parent PR #131; extended benchmarks use the existing Go benchmark entry point.
APK artifacts
Built from commit
7720c0aeby CI run #446.Artifacts expire after 14 days. Neither APK uses the MegaProxy release key.