Skip to content

Commit 59a96c8

Browse files
committed
fix: remove small payload uncompressed path
After benchmarking this proved to be not very useful in practice, compression is basically the same.
1 parent 8301b1b commit 59a96c8

3 files changed

Lines changed: 9 additions & 22 deletions

File tree

src/room/rpc/RpcClientManager.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import type Participant from '../participant/Participant';
1313
import { Future, compareVersions } from '../utils';
1414
import type { ByteStreamReader } from '../data-stream/incoming/StreamReader';
1515
import {
16-
COMPRESS_MIN_BYTES,
1716
DATA_STREAM_MIN_BYTES,
1817
MAX_LEGACY_PAYLOAD_BYTES,
1918
type PerformRpcParams,
@@ -157,7 +156,7 @@ export default class RpcClientManager {
157156
const payloadBytes = byteLength(payload);
158157

159158
let mode: 'regular' | 'compressed' | 'compressed-data-stream' = 'regular';
160-
if (remoteClientProtocol >= CLIENT_PROTOCOL_GZIP_RPC && payloadBytes > COMPRESS_MIN_BYTES) {
159+
if (remoteClientProtocol >= CLIENT_PROTOCOL_GZIP_RPC) {
161160
mode = 'compressed';
162161
}
163162
if (mode === 'compressed' && payloadBytes > DATA_STREAM_MIN_BYTES) {

src/room/rpc/RpcServerManager.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type { ByteStreamReader } from '../data-stream/incoming/StreamReader';
88
import type OutgoingDataStreamManager from '../data-stream/outgoing/OutgoingDataStreamManager';
99
import type Participant from '../participant/Participant';
1010
import {
11-
COMPRESS_MIN_BYTES,
1211
DATA_STREAM_MIN_BYTES,
1312
MAX_LEGACY_PAYLOAD_BYTES,
1413
RPC_DATA_STREAM_TOPIC,
@@ -178,11 +177,8 @@ export default class RpcServerManager {
178177
}
179178

180179
// Medium response: compress inline
181-
if (
182-
callerClientProtocol >= CLIENT_PROTOCOL_GZIP_RPC &&
183-
responseBytes > COMPRESS_MIN_BYTES
184-
) {
185-
const compressed = await gzipCompress(response!);
180+
if (callerClientProtocol >= CLIENT_PROTOCOL_GZIP_RPC) {
181+
const compressed = await gzipCompress(response);
186182
await this.engine.publishRpcResponseCompressed(callerIdentity, requestId, compressed);
187183
return;
188184
}
@@ -299,10 +295,7 @@ export default class RpcServerManager {
299295
return;
300296
}
301297

302-
if (
303-
callerClientProtocol >= CLIENT_PROTOCOL_GZIP_RPC &&
304-
responseBytes > COMPRESS_MIN_BYTES
305-
) {
298+
if (callerClientProtocol >= CLIENT_PROTOCOL_GZIP_RPC) {
306299
// Medium response: compress inline
307300
const compressed = await gzipCompress(response);
308301
await this.engine.publishRpcResponseCompressed(callerIdentity, requestId, compressed);

src/room/rpc/utils.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,16 @@ export class RpcError extends Error {
139139
}
140140

141141
/*
142-
* Maximum payload size for RPC requests and responses when using the legacy (uncompressed / no data
143-
* streams) path. If a payload exceeds this size and the remote client does not support compression,
142+
* Maximum payload size for RPC requests and responses for clients with a clientProtocol of less
143+
* than CLIENT_PROTOCOL_GZIP_RPC.
144+
*
145+
* If a payload exceeds this size and the remote client does not support compression,
144146
* the RPC call will fail with a REQUEST_PAYLOAD_TOO_LARGE(1402) or RESPONSE_PAYLOAD_TOO_LARGE(1504) error.
145147
*/
146148
export const MAX_LEGACY_PAYLOAD_BYTES = 15360; // 15 KB
147149

148150
/**
149-
* Payloads smaller than this are sent uncompressed (legacy path).
150-
* @internal
151-
*/
152-
export const COMPRESS_MIN_BYTES = 1024; // 1 KB
153-
154-
/**
155-
* Payloads at or above this size are sent via a data stream instead of inline.
151+
* Payloads above this size are sent via a data stream instead of inline.
156152
* @internal
157153
*/
158154
export const DATA_STREAM_MIN_BYTES = 15360; // 15 KB
@@ -163,7 +159,6 @@ export const DATA_STREAM_MIN_BYTES = 15360; // 15 KB
163159
*/
164160
export const RPC_REQUEST_ID_ATTR = 'lk.rpc_request_id';
165161

166-
167162
/** @internal */
168163
export const RPC_REQUEST_METHOD_ATTR = 'lk.rpc_request_method';
169164

0 commit comments

Comments
 (0)