Skip to content

Commit a2a93f4

Browse files
committed
Remove cold-start latency from the VPN by blocking
Previously, if there was no data available the VPN would pause for 100ms, because the connection was non-blocking. This adds ~50ms to request startup whenever the connection goes quiet, which is pretty noticeable! This tiny change and that goes away (ping over wifi is now ~10ms vs 4ms direct).
1 parent 94a6613 commit a2a93f4

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

app/src/main/java/tech/httptoolkit/android/ProxyVpnRunnable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ProxyVpnRunnable(
8484
packet.clear()
8585
} else {
8686
try {
87-
Thread.sleep(100)
87+
Thread.sleep(10)
8888
} catch (e: InterruptedException) {
8989
Log.d(TAG, "Failed to sleep: " + e.message)
9090
}

app/src/main/java/tech/httptoolkit/android/ProxyVpnService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class ProxyVpnService : VpnService(), IProtectSocket {
148148
vpnInterface = Builder()
149149
.addAddress(VPN_IP_ADDRESS, 32)
150150
.addRoute(ALL_ROUTES, 0)
151+
.setBlocking(true) // We use a blocking loop to read this in ProxyVpnRunnable
151152
.apply {
152153
// We exclude ourselves from interception, so we can still make network requests
153154
// separately, primarily because otherwise pinging with isReachable is recursive.

0 commit comments

Comments
 (0)