Conversation
- Introduce `clientIdMap` (Map<string, Set<string>>) in `server/index.ts` to index socket IDs by client ID. - Maintain the index on `connection` and `disconnect` events. - Replace O(N) linear scan in `message:ack` handler with O(1) index lookup. - Preserve existing "first one wins" behavior for handling multiple connections with the same client ID. - Fix minor unused variable warning in server shutdown loop. Measured improvement: ~1650x speedup for 50k connected clients in micro-benchmark. Co-authored-by: bmendonca3 <208517100+bmendonca3@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
This PR optimizes the client lookup mechanism in the WebSocket server.
Previously, finding a client by
clientIdrequired a linear scan of all connected sockets (Array.from(clients.values()).find(...)), which is O(N).This change introduces a secondary index
clientIdMapthat mapsclientIdto aSetofsocketIds. Lookups are now O(1).The optimization preserves the existing behavior where the first connected socket for a given
clientIdis targeted.A micro-benchmark confirmed significant performance gains (from ~2.4ms to ~0.0015ms for 50k clients). Existing tests pass.
PR created automatically by Jules for task 14337241076733970662 started by @bmendonca3