Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(WebSocket): implement client-side permessage-deflate compression #18221

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Jarred-Sumner
Copy link
Collaborator

Summary

  • Implements WebSocket permessage-deflate compression extension (RFC7692) for the WebSocket client
  • Uses libdeflate for efficient compression/decompression
  • Handles all parameters specified in RFC7692 (window bits, context takeover)
  • Automatically negotiates compression during connection handshake

Performance Optimizations TODO

This implementation needs further optimization before it's production-ready:

  • Reduce unnecessary memory allocations, particularly in the compression/decompression paths
  • Create a shared buffer pool to avoid repeated allocations
  • Optimize the parameter parsing during handshake
  • Improve buffer size heuristics to minimize reallocations
  • Benchmark against different compression level strategies

Test plan

  • Connect to a WebSocket server that supports permessage-deflate compression
  • Send and receive messages that would benefit from compression
  • Verify reduced payload sizes and proper handling of the RSV1 bit
  • Test with different context takeover and window bit configurations

🤖 Generated with Claude Code

Jarred-Sumner and others added 5 commits March 15, 2025 14:56
This adds support for the permessage-deflate WebSocket extension (RFC7692) to
Bun's WebSocket client. The implementation:

- Negotiates compression parameters during the WebSocket handshake
- Compresses outgoing messages using libdeflate
- Decompresses incoming messages
- Handles context takeover settings appropriately
- Implements window size parameters
- Includes proper RSV1 bit handling
- Follows RFC7692 specification for frame processing

This allows WebSocket connections to use significantly less bandwidth for
repetitive or compressible data like JSON or text content.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@robobun
Copy link

robobun commented Mar 15, 2025

Updated 7:48 PM PT - Mar 15th, 2025

@Jarred-Sumner, your commit c8a3a84 has 8 failures in Build #13367:


🧪   try this PR locally:

bunx bun-pr 18221

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants