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: threshold #1

Merged
merged 9 commits into from
Dec 4, 2024
Merged

feat: threshold #1

merged 9 commits into from
Dec 4, 2024

Conversation

leonardoventurini
Copy link
Owner

@leonardoventurini leonardoventurini commented Nov 9, 2024

This PR adds a new threshold option to control when compression is applied to WebSocket messages. Messages smaller than the threshold will skip compression entirely, which can improve performance by avoiding unnecessary compression overhead on small payloads.

Key Changes

  • Added new threshold configuration option (defaults to 0 - always compress)
  • Skip compression for messages smaller than threshold size
  • Optimized buffer handling for compressed messages using Buffer.allocUnsafe
  • Updated GitHub Actions to test only on modern Node.js versions (20+)
  • Added comprehensive test coverage for threshold behavior
  • Bumped version to 0.1.8
  • Renamed package to permessage-deflate2 to avoid conflicts

Why This Matters

Small messages often don't benefit from compression and can actually become larger due to compression overhead. By allowing users to set a minimum size threshold, we can:

  1. Improve performance by avoiding unnecessary compression work
  2. Reduce CPU usage on high-traffic WebSocket servers
  3. Potentially reduce actual message sizes when compression would be counterproductive

Breaking Changes

  • Dropped support for Node.js versions before 20
  • Package renamed to permessage-deflate2

Usage

deflate = deflate.configure({
  threshold: 100, // Skip compression for messages < 100 bytes
  // ... other options
});

@leonardoventurini leonardoventurini merged commit 2e5ba20 into main Dec 4, 2024
3 checks passed
@leonardoventurini leonardoventurini deleted the threshold branch December 4, 2024 14:44
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