Download Latest Version v20.75.0 source code.tar.gz (294.4 kB)
Email in envelope

Get an email when there's a new version of µWebSockets

Home / v20.72.0
Name Modified Size InfoDownloads / Week
Parent folder
README.md 2025-01-28 1.9 kB
v20.72.0 source code.tar.gz 2025-01-28 289.6 kB
v20.72.0 source code.zip 2025-01-28 349.1 kB
Totals: 3 Items   640.6 kB 0

Prepared Messages for Efficient Sending and Publishing

A feature from v0.14, previously removed due to lack of interest, has now been revived! Check out the demo in examples/Precompress.cpp to see it in action.

A PreparedMessage is a message that is compressed once but can be sent multiple times. This requires the SHARED_COMPRESSOR option but works with any decompressor option. The core idea is to decouple the compression process from the act of sending the message, reducing the per-socket computational overhead of compression to near zero.

Ideal Use Case

This feature is ideal for scenarios where you need to send snapshots of a data stream to multiple recipients. Here’s how it could work:

  • A timer periodically creates a new PreparedMessage containing the latest snapshot of the data (e.g., every 500ms).
  • When a WebSocket connects, it receives the most recent prepared snapshot, followed by incremental updates (deltas) from that point onward.
  • If the snapshot is large, pre-compressing it as a PreparedMessage eliminates the need for repeated compression, significantly reducing overhead for each socket.

Important Notes

  • This feature only works with SHARED_COMPRESSOR. Using a sliding window compression method is incompatible with this optimization.
  • New methods have been added to support this feature:
  • WebSocket::sendPrepared
  • App::publishPrepared
  • Loop::prepareMessage
  • You can create PreparedMessage objects on any thread, as long as that thread has its own Loop (which is automatically created for you via Loop::get()). However, in such cases, you must handle synchronization manually. Refer to examples/Precompress.cpp for guidance.

This release introduces the interface and its initial implementation. While memory-saving optimizations are not included in this release, they may be addressed in future updates.

Source: README.md, updated 2025-01-28