-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Use bytes::Bytes instead of Vec<u8> to represent binary payloads #285
Conversation
b7e5e24
to
71a7922
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make a bigger review tomorrow. I only have a question for the moment.
Did you consider to change the packet_buf
in the v3_binary_encoder
from Vec
to Bytes
and also did you think about the optimization we could get by using the Bytes
struct (I think about fast cloning and also maybe no continuous array so that is it possible to have faster encoding/decoding for polling).
That's why I wanted to move to Bytes
at the origin but I didn't check this deep enough for the moment. If you want, feel free to do it in this PR, if you prefer to work on other things I'll do this in another PR (if I find optimisation that could be done with Bytes
).
I did do that. Or are you mean the decoder, not the encoder? If so, I did look at that, but they both use |
71a7922
to
4f95065
Compare
I added a little commit to refactor the For further optimisations, here we could switch from I only have one remaining question maybe your opinion will help me to decide. What do you think between having public interface requiring |
Yeah, that seems like a good idea to me. Are there any downsides to that? I guess larger code size for each monomorphized function if the user uses several different things that implement One thing that will be an API break is changing the argument type in |
It is mainly the socketioxide API which is important. It is not a problem to change the engineioxide API. |
@kelnos do you plan to implement this anytime soon ? Once it is done we can merge this. If you don't have enough free time for this I can work on it and merge the PR if your ok with this. |
Ah, sorry, I completely forgot there was more to do here & was going to ping you about getting it merged. Sure, I can take care of that. |
Hm, I'm unable to run the tests now; it looks like you changed how the test harness works, but when I:
And then run
Not really sure what's expected here. Also in |
Ah, looks like you put |
615409b
to
642a9b6
Compare
Ok started working on this after finishing the rebase and fixing conflicts. I'm a little concerned about extra overhead here, though. For example: impl ConfOperators {
pub fn bin<B: Into<Bytes>>(mut self, binary: Vec<B>) -> Self {
self.binary = binary.into_iter().map(Into::into).collect();
self
}
} Even in the case where a |
1109c80
to
eec1c47
Compare
The doc on the collect in vec specify that in certain case it will do the mutation "in place" without allocating for a new Maybe we could try to benchmark this but I don't think it is a limiting factor. According to the implementation, our use case matches the optimization: |
Ah, neat. And while that's only an implementation detail, that seems like something that's unlikely to change. |
Also I just realized I force-pushed without first pulling your additional commit that refactored the |
This replaces the use of Vec<u8>.
This replaces the use of Vec<u8>.
eec1c47
to
adf5f66
Compare
At any rate, I think I made the changes you asked for. |
Thanks, I'll review this this week! :) |
e799085
to
032ea4b
Compare
I added some other changes:
Sorry I should have been more clear on what API bits should be flexible and what can stay fixed. |
No worries and thank you for taking care of it! |
As requested, moved to a separate PR :)