Skip to content

Benchmark MASQUE, HTTPS and SSH; reduce MASQUE UDP allocations - #133

Merged
andre487 merged 1 commit into
mainfrom
benchmark-transports
Oct 27, 2026
Merged

andre487 merged 1 commit into
mainfrom
benchmark-transports

Conversation

@andre487

@andre487 andre487 commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Pull request stack

GitHub stack #135.

Merge order: #131 → #132 → #133.

Base: #132. Each PR contains only its own change relative to its parent. After merging lower layers, use gh stack sync to update local tracking and restack the remaining branches.

Result

Add reproducible encrypted-loopback benchmarks for MASQUE, HTTPS and SSH, and remove two measured per-datagram allocation sources in MASQUE. This PR is stacked on #132, which inherits the Fastlane benchmark runner from #131.

MASQUE now parses the existing byte slice with quicvarint.Parse instead of allocating bytes.Reader. Its UDP peer checks compare valid numeric endpoints directly, preserving IP/port/IPv6 zone checks and the textual fallback for other address types. Apply the same peer check to its direct-UDP wrapper. QUIC ownership/copies, datagram limits, deadlines, trust and source-validation policy remain intact.

Benchmarks

Run sequentially through bundle exec fastlane android native_benchmarks with bench:BenchmarkTransportMASQUE, bench:BenchmarkTransportHTTPS, then bench:BenchmarkTransportSSH. They are opt-in; the default CPU-only suite remains unchanged.

  • MASQUE: encrypted streams at 64/1400/32768 bytes and CONNECT-UDP at 64/1200 bytes, fixed versus per-exchange deadlines.
  • HTTPS: real CONNECT over negotiated HTTP/1.1, HTTP/2 and preferred HTTP/3, with protocol-selection assertions.
  • SSH: actual encrypted direct-tcpip channels, disposable password and pinned ephemeral host key, using the OpenSSH-style client profile and a local x/crypto/ssh peer.

Ten 200 ms samples per scenario on Apple M4 Pro, GOMAXPROCS=1. All peers bind loopback and echo inside the proxy/channel; no external origin, Internet, personal credentials or Docker is used. One operation is a warm sequential round trip, including both encrypted endpoints in the process-wide CPU/allocation metrics; bytes count both directions. Setup and first exchange are outside the timer. SSH stalls have a closing watchdog because native SSH channels do not support socket deadlines.

Findings

MASQUE UDP loses 7 allocations and approximately 112 B per round trip, consistently for both sizes and deadline policies:

UDP deadline policy Before allocations/op After allocations/op
Fixed 56 49
Renewed per exchange 60 53

These totals include QUIC and the echo peer, not just the client wrapper. Unchanged stream controls also showed timing drift, so no end-to-end latency improvement is claimed.

HTTPS HTTP/2 profiles primarily show system I/O and TLS/HTTP2 library work; the HTTP/3 bulk allocation profile is dominated by UDP/QUIC packet handling. SSH's allocation profile attributes roughly 95% to x/crypto/ssh.connectionState.readPacket. No comparable avoidable application-layer operation was established in those stream paths; no third-party library edits were made.

EN/RU documentation describes commands, profile analysis, measurement boundaries and limitations: no cold handshakes, concurrency/loss/stress, jump chains, sustained rotation/rekey, TUN/JNI or Android bandwidth claims. Real GOST/OpenSSH interoperability remains the separate Docker integration suite.

Validation

  • All 338 native tests passed with the race detector on the complete Add reproducible native core performance benchmarks #131 → Avoid per-datagram SOCKS5 reply address allocations #132 → Benchmark MASQUE, HTTPS and SSH; reduce MASQUE UDP allocations #133 stack (the initial isolated transport run passed 322 tests).
  • Separate MASQUE, HTTPS and SSH targeted race suites passed in that order.
  • All 19 transport scenarios ran ten samples each, plus the MASQUE before/after comparison.
  • CPU/heap profiles generated for MASQUE UDP, HTTPS HTTP/2 and HTTP/3, and SSH; analyzed with pprof and comparisons with benchstat.
  • UDP peer-policy equivalence matrix, nil/mapped/zone/port checks and a zero-allocation check for numeric peers.
  • Actual QUIC context-prefix regression covers nonzero/truncated contexts and all legal zero-context encoding lengths.
  • SSH fixture regressions reject incorrect host key, password and target and verify successful encrypted echo.

APK artifacts

Built from commit a19cf5a9 by CI run #448.
Artifacts expire after 14 days. Neither APK uses the MegaProxy release key.

@andre487
andre487 added this pull request to stack #134 October 27, 2026 15:42
@andre487
andre487 force-pushed the benchmark-transports branch from c35a1f2 to 30505e6 Compare October 27, 2026 15:44
@andre487
andre487 removed this pull request from stack #134 October 27, 2026 15:49
@andre487
andre487 changed the base branch from native-benchmarks to optimize-socks5-udp October 27, 2026 15:50
@andre487
andre487 added this pull request to stack #135 October 27, 2026 15:50
@andre487
andre487 force-pushed the benchmark-transports branch from 30505e6 to 448ab5b Compare October 27, 2026 15:51
Base automatically changed from optimize-socks5-udp to main October 27, 2026 16:06
@andre487
andre487 force-pushed the benchmark-transports branch from 448ab5b to a19cf5a Compare October 27, 2026 16:06
@andre487
andre487 merged commit 22495ba into main Oct 27, 2026
15 checks passed
@andre487
andre487 deleted the benchmark-transports branch October 27, 2026 16:21
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.

1 participant