Skip to content

Transmit only single frame in Write when compression enabled too #435

Closed

Description

@andersroos

Hi I am experiencing a pretty weird behavior and I am unsure if this is intentional or not.

We have had problems with bad client performance when reading data from a websocket in a game client based on Unreal Engine.

I have investigated this and with compression enabled each message is chopped up in tiny frames (the problem surfaced when we run with 1.8.7 which had compression on by default). The problem with Unreal is that it only reads one frame per client tick (~8 milliseconds) by default.

When I inspect this in Wireshark it looks like every other frame has a 236 byte payload and every other has a 4 byte payload.

I also run it in the debugger and it looks like the server will send a frame for each write call from the flate lib (github.com/klauspost/compress) and it has a hard coded bufferFlushSize set to 240 which in turn causes all those individual calls to writeFrame.

Is this intentional?

Activity

  1. nhooyr commented on Feb 21, 2024

    @nhooyr
    Contributor

    Are you using Write or Writer? Write should write in a single frame whereas Writer unfortunately does write in two frames.

    If you are using Write it's possible I forgot to add the code necessary to make it use a single frame with compression enabled.

  2. nhooyr commented on Feb 21, 2024

    @nhooyr
    Contributor

    Also are you using the latest version or are you on 1.8.7 still?

  3. andersroos commented on Feb 21, 2024

    @andersroos
    Author

    Thanks for the response.

    I have tested on 1.8.10 and it is the same behavior if compression is enabled (CompressionMode: websocket.CompressionNoContextTakeover).

    The code uses Write (this method: https://github.com/nhooyr/websocket/blob/e3a2d32f704fb06c439e56d2a85334de04b50d32/write.go#L44).

    I can make a minimal example to reproduce if it's helpful.

  4. nhooyr commented on Feb 21, 2024

    @nhooyr
    Contributor

    No need I see it, the problem is here: https://github.com/nhooyr/websocket/blob/e3a2d32f704fb06c439e56d2a85334de04b50d32/write.go#L110

    I need to extend this code to allow for single frame compression.

  5. added this to the v1.9.0 milestone on Feb 21, 2024
  6. changed the title [-]Tiny frames when compression is enabled[/-] [+]Transmit single frame in Write when compression enabled too[/+] on Feb 21, 2024
  7. changed the title [-]Transmit single frame in Write when compression enabled too[/-] [+]Transmit only single frame in Write when compression enabled too[/+] on Feb 21, 2024
  8. nhooyr commented on Feb 21, 2024

    @nhooyr
    Contributor

    I would suggest disabling compression till I get to this. Hopefully within the next 2 months.

  9. andersroos commented on Feb 21, 2024

    @andersroos
    Author

    I would suggest disabling compression till I get to this. Hopefully within the next 2 months.

    Thank you, will do.

  10. mafredri commented on Dec 19, 2025

    @mafredri
    Member

    @andersroos, you've been waiting a while, but a fix was just merged in. No release yet, but it's there if you want to try it out.

  11. andersroos commented on Dec 19, 2025

    @andersroos
    Author

    @andersroos, you've been waiting a while, but a fix was just merged in. No release yet, but it's there if you want to try it out.

    Hey! Thank you!

    Will test it for sure, but can't say if it will be before or after release yet.

  12. kornes commented on Mar 13, 2026

    @kornes

    I ran into exact same issue with compressed messages, and can confirm #552 pr fixed it for me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions