-
Notifications
You must be signed in to change notification settings - Fork 227
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
message: support bytes::Bytes
as a payload type
#462
Conversation
I am not sure if this is just on my end but when I run
and when running for this PR/branch:
|
Thanks, benchmarking is a good thing! I'll investigate what's going on. UPD: Ok, when I run write benchmarks, I get +/- 5% difference pretty often, even without changes, but 35% of a difference is quite stark. Apparently, using Anyway, if the performance cost is so high, then perhaps |
34f14bd
to
663d3da
Compare
I think this is a step in the right direction. Nice to see the write bench was useful :) I think we would benefit from some more scenarios benched in this way, binary writes & reads etc. If I can find some time I'll raise a PR proposing some more. |
@alexheretic IIRC, I looked at the If implemented correctly, converting to |
I noticed you can use this branch for writing text too with I struggled to produce a benchmark win using that though, even though it should really eliminate allocation. Maybe allocation just isn't significant enough to the other write work currently? I raised a PR with the extra benches: #463 |
To make it pass `tungstenite`'s CI for min Rust version
bytes::Bytes
bytes::Bytes
as a payload type
I don't expect any improvements in benchmarks from this PR, at least for the benches in question. The reason is that this change does not really switch to
In other words, folks that used That's why there was no difference in performance when I compared it to a master branch (the benchmarks in master use owned data). However, there is a difference when testing it against your new benchmarks. This PR version shows, on average, a 4-5% decrease in performance in reading and writing. I'm still unsure what this could be attributed to, given that the underlying type for all benchmarks remains the same even for this PR (no I then modified your writing benchmark for the use cases explicitly mentioned in #96. Instead of creating small messages in a loop, I made a moderately sized message (1KB) and sent it in that loop in the writing benchmark. I ran it on this branch and then compared it to the version that uses
So the master version is 126% slower than the version that uses The net result of the changes is that performance for general use cases drops by about 5% (and I'm not sure why, apart from the guess mentioned above). However, for server users, the performance wins may be above 125% if they specifically choose to use Tbh, if that small performance drop for the general use case could somehow be eliminated, then switching to the new |
588c27a
to
5a5586a
Compare
In fact, |
fwiw I didn't see much difference between the branches in the new benches. Though I did convert them to this branch slightly differently and I think I stumbled upon Now I run using
|
Thanks! Yep, this roughly aligns with the results that I'm getting.
I'm thinking about adding this benchmark. This means that the version in |
tbh I don't see the minor benches perf regression as blocking this PR. The scenario where a server broadcasts a message to N clients is clearly a massive advantage to supporting Bytes. The regression reported by the benches is not large. |
I got carried away a bit trying to adding text support 😅 #465 |
Awesome! Since yours is rebased on top of this branch, I'll merge it instead of integrating these two separately! So far, it seems like no one objected, so I think we're good to go! |
Preface
Recently, there has been another PR trying to solve the long-standing #96.
The issue had already been addressed in another PR that has been there for a while. I've noticed that I even approved the PR a while ago. Yet, it has not been merged for reasons I can't remember (AFAIR, I was waiting for another approval from another maintainer(s)/active users, but somehow it went stalled). Now, the discussions on the PR and the issue are so long that it's hard to get a brief overview of the current state and blockers, if any.
Yesterday, I quickly went through #175 and the discussions on the issue to see if I could come up with something that would give it at least some resolution (#175 has conflicts with a master branch) and create a small and easy-to-review PR to see if it's something that we can merge rather quickly.
TL;DR
Essentially, the only thing this one changes is that all binary messages are backed by(see #462 (comment)). I also have not touched the text messages for now (as there have been several proposals, and I'm not sure there is a consensus as to which one is the best).Bytes
instead of aVec<u8>
. The distinction betweenOwned
andShared
is internal and invisible to the end user.So the question is if we are good with having(see #462 (comment)); the main concern for usingBytes
instead of aVec<u8>
or if we want to expose thatPayload
type and makeMessage
rely on it (like in #175). If I'm not mistaken, the cost ofBytes
is negligibleBytes
as the type for theMessage::Binary
was the additional allocation/copy of a buffer that is done before applying a mask (sinceBytes
is immutable), and #175 did so by creating a copy before applying a mask. I changed it so we don't make this copy ifBytes
has unique access.Does it make any sense, or did I miss something?
@Dushistov, @sdroege, @francois-random: I decided to mention you folks since you participated in the discussion the most in the past year and seem interested in the outcome of this one. I'm going to also mention @alexheretic (you seem to be interested in performance-related improvements 🙂).
--
Fixes #96
Supersedes #175 if we agree that it's a sensible solution.