-
Notifications
You must be signed in to change notification settings - Fork 14
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
Question about iolists #36
Comments
If I remember correctly, iolists don't work well for websocket because iodata must be binaries: %% erlang.erl in the OTP codebase
%% ..
-type binary() :: <<_:_*8>>.
-type bitstring() :: <<_:_*1>>.
%% ..
-type byte() :: 0..255.
%% ..
-type iodata() :: iolist() | binary().
-type iolist() :: maybe_improper_list(byte() | binary() | iolist(), binary() | []).
%% .. while the frames are bitstrings: mint_web_socket/lib/mint/web_socket/frame.ex Lines 120 to 128 in f44a35e
We already send bitstrings through |
@the-mikedavis Thanks for the explanation, that makes sense. So, if the payload has to be a binary in order to mask its data then it seems like it probably won't work to use iolists, as whatever payload you pass has to become a binary regardless. Unless there is some case where it's faster to serialize your payload to iolists with whatever encoding you happen to be using (in my case, CBOR) and then have I'm not confident that the former would yield higher throughput than the latter, even if it did generate less intermediate garbage or have some other kind of benefit like easier payload construction, etc. Even if there was such a benefit, I think it would be workload dependent, as you'd still have to call This is an aside but I just want to explain my motivation for opening this issue at all: my application does a fair amount of websocket traffic with CBOR-encoded payloads on pretty limited embedded hardware, to the point where CBOR encoding is a large portion of our benchmarked CPU. The Elixir In any case thanks for the response and for the excellent library, we may still end up using |
Ah actually I just realized the frames are always binaries:
(so all frames will have bits divisible by 8) So the only part of switching to iodata that is tricky is adding a new version of the masking function that will work on iodata. Here's what we have for binaries now: mint_web_socket/lib/mint/web_socket/frame.ex Lines 175 to 200 in f44a35e
That function could also be rewritten to return iodata - we could build the EDIT: I have some of my thoughts on implementing this here: https://github.com/elixir-mint/mint_web_socket/compare/iodata. It just needs the masking implementation for iodata. |
Hey all, thanks for the library. I don't have an issue to report, just a question.
I see that the signature of encode, specifically for a
{:binary, data}
payload requires that data be a binary, via theis_binary
guard in theis_friendly_frame
guard:https://github.com/elixir-mint/mint_web_socket/blob/main/lib/mint/web_socket/frame.ex#L67
Is this requirement for the data to be strictly a binary rather than iodata broadly due to something in the websocket protocol itself? I don't know the inner workings of the websocket protocol and I'm accustomed to using iolists via gentcp, etc., for performance, so I'm just curious if it would ever be possible to send an iolist in this library (or any others).
Thank you!
The text was updated successfully, but these errors were encountered: