perf(server): negotiate permessage-deflate on the websocket #4705
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 3 commits into
main fromrefs/pull/4705/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- patches/@effect__platform-node@4.0.0-beta.102.patch lines 37 to 39OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +19,21 @@19+ wss.close(() => resume(Effect.void));20+ })).pipe(Scope.provide(scope), Effect.cached);21+22+23+24+25+26+ const address = server.address()!27+28+ const wss = yield* Effect.acquireRelease(29+- Effect.sync(() => new NodeWS.WebSocketServer({ noServer: true })),30++ Effect.sync(() =>31++ new NodeWS.WebSocketServer({32++ noServer: true,33++ // Negotiate permessage-deflate with clients that offer it; clients that34++ // don't still get uncompressed frames on their connection. Context35++ // takeover stays enabled (ws default) so the compression window is36++ // shared across frames; threshold skips compression for tiny frames.37++ perMessageDeflate: {38++ threshold: 51239++ }
- patches/@effect__platform-bun@4.0.0-beta.102.patch line 22Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,16 @@1+2+3+4+5+6+ ...options,7+ fetch: handlerStack[0],8+ websocket: {9++ // Negotiate permessage-deflate with clients that offer it; clients that10++ // don't still get uncompressed frames on their connection. Dedicated11++ // compressors keep per-connection sliding windows (context takeover) so12++ // the compression dictionary is shared across frames.13++ perMessageDeflate: {14++ compress: "dedicated",15++ decompress: "dedicated"16++ },
- @@ -3081,3 +3081,20 @@30813081 }).pipe(Effect.provide(NodeHttpServer.layerTest)),30823082 );308330833084+ it.effect("negotiates permessage-deflate with clients that offer it", () =>3085+ Effect.gen(function* () {3086+ yield* buildAppUnderTest();3087+3088+ const { cookie, url } = parseSessionCookieFromWsUrl(yield* getWsServerUrl("/ws"));3089+ const openSocket = (perMessageDeflate: boolean) =>3090+ Effect.acquireRelease(3091+ Effect.callback<NodeSocket.NodeWS.WebSocket, Error>((resume) => {3092+ const socket = new NodeSocket.NodeWS.WebSocket(url, {3093+ perMessageDeflate,3094+ ...(cookie ? { headers: { cookie } } : {}),3095+ });3096+ socket.on("open", () => resume(Effect.succeed(socket)));3097+ socket.on("error", (error) => resume(Effect.fail(error)));3098+ }),3099+ (socket) => Effect.sync(() => socket.close()),3100+ );
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
✨ Finishing Touches
📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share