Skip to content

Conversation

rkistner
Copy link
Contributor

@rkistner rkistner commented Aug 26, 2025

Builds on #329.

This enables permessage-deflate for websockets connections, if the client indicates support. This is the only standardized compression extension supported for websockets.

Compression is per message (as implied by the name), but compression context is preserved across messages.

In my tests with synthetic data, 400MiB plaintext (bson) data is compressed into around 87MiB of compressed data, or 22% of the original size. This is still more than we get with zstd-compressed JSON data, but it is a significant reduction.

I'm seeing around 15% increase in CPU usage on the service when this is enabled, which is a worthwhile trade-off in my opinion.

This should work out-of-the-box with all major browsers - tested on Chrome and Firefox.

Enabling permessage-deflate is fairly simple - it primarily involved some performance testing of the various parameter combinations. The larger part of this PR is for tracking whether compression is used, and the actual number of bytes sent (for logging and metrics).

Copy link

changeset-bot bot commented Aug 26, 2025

🦋 Changeset detected

Latest commit: 03ac79d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@powersync/service-rsocket-router Minor
@powersync/service-core Minor
@powersync/service-image Minor
@powersync/service-types Patch
@powersync/service-module-core Patch
@powersync/service-core-tests Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres-storage Patch
@powersync/service-module-postgres Patch
test-client Patch
@powersync/service-schema Minor
@powersync/lib-service-postgres Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@rkistner rkistner mentioned this pull request Aug 26, 2025
3 tasks
Base automatically changed from compression to main August 27, 2025 09:09
@rkistner rkistner force-pushed the permessage-deflate branch from c10d811 to 0cde51b Compare August 27, 2025 09:10
@rkistner rkistner requested a review from Copilot August 27, 2025 09:11
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables permessage-deflate compression for WebSocket connections to reduce bandwidth usage. The compression is applied per message while preserving context across messages, achieving significant data reduction (78% compression in tests) with a 15% CPU increase trade-off.

Key changes:

  • Added permessage-deflate configuration to WebSocket server with optimized parameters
  • Implemented WebSocketTracker class to monitor compression encoding and track bytes written
  • Extended connection tracking throughout the request pipeline to support compression metrics

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
socket-route.ts Added compression tracking setup and byte counting for compressed streams
types.ts Extended stream payload interface to include WebSocket connection reference
WebsocketDuplexConnection.ts Implemented WebSocketTracker class and added compression detection logic
ReactiveSocketRouter.ts Configured permessage-deflate options and integrated connection tracking
rich-fans-care.md Added changeset documentation for the compression feature

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@rkistner rkistner requested a review from simolus3 August 27, 2025 09:13
@rkistner rkistner merged commit f56acce into main Aug 27, 2025
21 checks passed
@rkistner rkistner deleted the permessage-deflate branch August 27, 2025 09:52
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