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

Is message cloning necessary when broadcasting? #271

Closed
rezu-jtr opened this issue Mar 19, 2023 · 1 comment
Closed

Is message cloning necessary when broadcasting? #271

rezu-jtr opened this issue Mar 19, 2023 · 1 comment

Comments

@rezu-jtr
Copy link

In a simple scenario, let's say a chat, when I have to broadcast all incoming websocket messages to all server participants, do I have to clone it as many times as the number of participants? The message is a text and is constant. Shouldn't I be allowed to send Arc<Message> to websocket streams/sinks?

@daniel-abramov
Copy link
Member

We have an old issue to address: snapview/tungstenite-rs#96 (comment)
I think we even agreed upon the solution (see discussion and linked issues), but it has not been fully implemented.

However, it does not mean that we won't perform any copies at all, since we would need to internally allocate a buffer when sending a message, so the message will still be copied (sort of), yet it would indeed be more efficient than copying the Message just before passing to the sink (given that the message will be copied and dropped after that). So yeah, for a broadcast scenario of a large message to many participants, we might be a bit inefficient.

I'm going to close this one since we have an open tracking issue for this. Once it's implemented in tungstenite, adapting tokio-tungstenite won't be a big deal.

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

No branches or pull requests

2 participants