Skip to content

Optimize connection pooling to reduce startup time with multiple chatrooms #26

@BP602

Description

@BP602

Problem

Currently, KickTalk creates individual connections for each chatroom, leading to poor performance with multiple chatrooms:

  • 21 separate KickPusher WebSocket connections (one per chatroom)
  • 21 separate 7TV WebSocket connections (one per chatroom)
  • 42 sequential emote API calls (21 × 2 services)
  • ~30 second startup time with 21 chatrooms

Current Architecture Issues

  1. Each chatroom creates its own KickPusher instance connecting to wss://ws-us2.pusher.com
  2. Each chatroom creates its own StvWebSocket instance connecting to wss://events.7tv.io/v3
  3. All connections initialize simultaneously without throttling
  4. No connection sharing or multiplexing

Proposed Solution

Implement connection pooling using Pusher's built-in multiplexing capabilities:

1. Shared KickPusher Connection

  • Current: 21 separate WebSocket connections
  • Optimized: 1 shared connection with 21 channel subscriptions
  • Use pusher.subscribe() for multiple channels on single connection

2. Shared 7TV Connection

  • Current: 21 separate WebSocket connections
  • Optimized: 1 shared connection with event multiplexing

3. Optimized Emote Fetching

  • Batch emote requests where possible
  • Cache global emotes (same across all channels)
  • Implement request throttling

4. Staggered Connection Initialization

  • Initialize connections in batches (3-5 per second)
  • Prioritize active/favorite channels first

Expected Performance Impact

  • Startup time: 30 seconds → 5-10 seconds
  • WebSocket connections: 42 → 2
  • API calls: 42 → ~21 (with caching)
  • Resource usage: Significantly reduced

Implementation Plan

  1. Create SharedKickPusher class for connection pooling
  2. Create SharedStvWebSocket class for 7TV multiplexing
  3. Implement batch emote fetching with caching
  4. Add staggered connection initialization
  5. Update ChatProvider.jsx to use shared connections

Files to Modify

  • src/renderer/src/providers/ChatProvider.jsx - Main connection logic
  • utils/services/kick/kickPusher.js - Pusher connection pooling
  • utils/services/seventv/stvWebsocket.js - 7TV connection pooling
  • utils/services/seventv/stvAPI.js - Emote caching
  • utils/services/kick/kickAPI.js - Emote batching

This optimization will significantly improve the user experience for users with multiple chatrooms open.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions