From 679b7fe1227c34988ad3c097eb170c9b9408249c Mon Sep 17 00:00:00 2001 From: f321x Date: Mon, 27 Oct 2025 18:28:09 +0100 Subject: [PATCH] interface: add warmup budget to PaddedRSTransport Adds a 1024 (unpadded) byte budget to the PaddedRSTransport below which messages are instantly flushed down the socket before the transport will beginn waiting for the buffer to reach MIN_PACKET_SIZE (1024). This allows to get the first couple of messages sent quickly when starting the wallet to improve UX. --- electrum/interface.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/electrum/interface.py b/electrum/interface.py index 606c9b9b4..1e42fce6d 100644 --- a/electrum/interface.py +++ b/electrum/interface.py @@ -328,6 +328,9 @@ class PaddedRSTransport(RSTransport): MIN_PACKET_SIZE = 1024 WAIT_FOR_BUFFER_GROWTH_SECONDS = 1.0 + # (unpadded) amount of bytes sent instantly before beginning with polling. + # This makes the initial handshake where a few small messages are exchanged faster. + WARMUP_BUDGET_SIZE = 1024 session: Optional['RPCSession'] @@ -361,6 +364,7 @@ class PaddedRSTransport(RSTransport): self._force_send or len(buf) >= self.MIN_PACKET_SIZE or self._last_send + self.WAIT_FOR_BUFFER_GROWTH_SECONDS < time.monotonic() + or self.session.send_size < self.WARMUP_BUDGET_SIZE ): return assert buf[-2:] in (b"}\n", b"]\n"), f"unexpected json-rpc terminator: {buf[-2:]=!r}" @@ -950,6 +954,7 @@ class Interface(Logger): proxy=self.proxy, transport=PaddedRSTransport, ) as session: + start = time.perf_counter() self.session = session # type: NotificationSession self.session.set_default_timeout(self.network.get_network_timeout_seconds(NetworkTimeout.Generic)) try: @@ -972,7 +977,7 @@ class Interface(Logger): raise GracefulDisconnect(e) if server_genesis_hash != constants.net.GENESIS: raise GracefulDisconnect(f'server on different chain: {server_genesis_hash=}. ours: {constants.net.GENESIS}') - self.logger.info(f"connection established. version: {ver}") + self.logger.info(f"connection established. version: {ver}, handshake duration: {(time.perf_counter() - start) * 1000:.2f} ms") try: async with self.taskgroup as group: