Skip to content

Commit 6b327f0

Browse files
t3dotggclaude
andcommitted
fix(server): address deflate review findings from bots
- Drop the dead `threshold` option from the Node patch: ws only honors `threshold` when context takeover is disabled, and measurement shows small frames compress 4.4x under the shared window anyway, so keeping takeover (without a threshold) is strictly better than the suggested contextTakeover:false + threshold combination (which measured 1.0x on sub-512B frames). - Switch the Bun patch's decompressor from dedicated to shared: uWebSockets' dedicated decompressor path can abort connections (close 1006) on valid DEFLATE input (uNetworking/uWebSockets.js#633). Server-to-client compression keeps the dedicated per-connection window, which is where the win lives. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent e70433c commit 6b327f0

3 files changed

Lines changed: 61 additions & 55 deletions

File tree

‎patches/@[email protected]‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
diff --git a/dist/BunHttpServer.js b/dist/BunHttpServer.js
2-
index 5fb0cbacc183b58e31a442badf4aef06bebcd592..c74a79be2657ab5e42f21351aa4c206dec13ec06 100644
2+
index 5fb0cbacc183b58e31a442badf4aef06bebcd592..2c3d2ea9a727b71e502f9e5c207340dfa0f63879 100644
33
--- a/dist/BunHttpServer.js
44
+++ b/dist/BunHttpServer.js
5-
@@ -45,6 +45,14 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
5+
@@ -45,6 +45,17 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
66
...options,
77
fetch: handlerStack[0],
88
websocket: {
99
+ // Negotiate permessage-deflate with clients that offer it; clients that
10-
+ // don't still get uncompressed frames on their connection. Dedicated
11-
+ // compressors keep per-connection sliding windows (context takeover) so
12-
+ // the compression dictionary is shared across frames.
10+
+ // don't still get uncompressed frames on their connection. A dedicated
11+
+ // compressor keeps a per-connection sliding window (context takeover) so
12+
+ // the compression dictionary is shared across server-to-client frames.
13+
+ // Decompression uses the shared decompressor: uWebSockets' dedicated
14+
+ // decompressor path can abort connections (close 1006) on valid DEFLATE
15+
+ // input — see https://github.com/uNetworking/uWebSockets.js/issues/633.
1316
+ perMessageDeflate: {
1417
+ compress: "dedicated",
15-
+ decompress: "dedicated"
18+
+ decompress: "shared"
1619
+ },
1720
open(ws) {
1821
Deferred.doneUnsafe(ws.data.deferred, Exit.succeed(ws));
1922
},
2023
diff --git a/src/BunHttpServer.ts b/src/BunHttpServer.ts
21-
index 9f2ac3dfc018e2d35c6f44785f1ce05e2e06fc7c..c1e5869fecc5d635ff89cd303feaf1efd6d06ef4 100644
24+
index 9f2ac3dfc018e2d35c6f44785f1ce05e2e06fc7c..84f3062d880d05f5a680ec89a5f0a1b78a3ba0dc 100644
2225
--- a/src/BunHttpServer.ts
2326
+++ b/src/BunHttpServer.ts
24-
@@ -90,6 +90,14 @@ export const make = Effect.fnUntraced(
27+
@@ -90,6 +90,17 @@ export const make = Effect.fnUntraced(
2528
...options as ServeOptions<R>,
2629
fetch: handlerStack[0],
2730
websocket: {
2831
+ // Negotiate permessage-deflate with clients that offer it; clients that
29-
+ // don't still get uncompressed frames on their connection. Dedicated
30-
+ // compressors keep per-connection sliding windows (context takeover) so
31-
+ // the compression dictionary is shared across frames.
32+
+ // don't still get uncompressed frames on their connection. A dedicated
33+
+ // compressor keeps a per-connection sliding window (context takeover) so
34+
+ // the compression dictionary is shared across server-to-client frames.
35+
+ // Decompression uses the shared decompressor: uWebSockets' dedicated
36+
+ // decompressor path can abort connections (close 1006) on valid DEFLATE
37+
+ // input — see https://github.com/uNetworking/uWebSockets.js/issues/633.
3238
+ perMessageDeflate: {
3339
+ compress: "dedicated",
34-
+ decompress: "dedicated"
40+
+ decompress: "shared"
3541
+ },
3642
open(ws) {
3743
Deferred.doneUnsafe(ws.data.deferred, Exit.succeed(ws))

‎patches/@[email protected]‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/dist/NodeHttpServer.js b/dist/NodeHttpServer.js
2-
index ab7c9354853032fefa192ebfa8ab2026bac6ddb7..6ecf13db641a9319c3ce6d0fb5dcf678cf75ba3b 100644
2+
index ab7c9354853032fefa192ebfa8ab2026bac6ddb7..505d94eb01850a5827e5205b077c86707767b8dc 100644
33
--- a/dist/NodeHttpServer.js
44
+++ b/dist/NodeHttpServer.js
55
@@ -83,7 +83,14 @@ export const make = /*#__PURE__*/Effect.fnUntraced(function* (evaluate, options)
@@ -11,15 +11,15 @@ index ab7c9354853032fefa192ebfa8ab2026bac6ddb7..6ecf13db641a9319c3ce6d0fb5dcf678
1111
+ // Negotiate permessage-deflate with clients that offer it; clients that
1212
+ // don't still get uncompressed frames on their connection. Context
1313
+ // takeover stays enabled (ws default) so the compression window is shared
14-
+ // across frames; threshold skips compression for tiny frames.
15-
+ perMessageDeflate: {
16-
+ threshold: 512
17-
+ }
14+
+ // across frames — that also makes small frames cheap to compress, so no
15+
+ // size threshold is set (ws only honors `threshold` when context takeover
16+
+ // is disabled).
17+
+ perMessageDeflate: true
1818
})), wss => Effect.callback(resume => {
1919
wss.close(() => resume(Effect.void));
2020
})).pipe(Scope.provide(scope), Effect.cached);
2121
diff --git a/src/NodeHttpServer.ts b/src/NodeHttpServer.ts
22-
index e18cd931f17c26d6ca985a2d1ece9e9d760851d3..758fd795c731200a9f58959e4be93817616b9ea7 100644
22+
index e18cd931f17c26d6ca985a2d1ece9e9d760851d3..a0868292b6bd2d20b1ba0487c46f21519411275f 100644
2323
--- a/src/NodeHttpServer.ts
2424
+++ b/src/NodeHttpServer.ts
2525
@@ -116,7 +116,18 @@ export const make = Effect.fnUntraced(function*(
@@ -33,10 +33,10 @@ index e18cd931f17c26d6ca985a2d1ece9e9d760851d3..758fd795c731200a9f58959e4be93817
3333
+ // Negotiate permessage-deflate with clients that offer it; clients that
3434
+ // don't still get uncompressed frames on their connection. Context
3535
+ // takeover stays enabled (ws default) so the compression window is
36-
+ // shared across frames; threshold skips compression for tiny frames.
37-
+ perMessageDeflate: {
38-
+ threshold: 512
39-
+ }
36+
+ // shared across frames — that also makes small frames cheap to
37+
+ // compress, so no size threshold is set (ws only honors `threshold`
38+
+ // when context takeover is disabled).
39+
+ perMessageDeflate: true
4040
+ })
4141
+ ),
4242
(wss) =>

0 commit comments

Comments
 (0)