-
Notifications
You must be signed in to change notification settings - Fork 78
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
Add support for zero-copy reading #29
Comments
I think this might be hard to achieve due to the stream-oriented API of cmp. The data might not always come from a memory buffer but could be streamed over network, be read from a file, etc. If you need such functions I suggest implementing them at the reader level instead. |
Hi! I see what you're saying. If you're reading individual members (like The reason I made that decision is that MessagePack stores its data in big-endian format. Converting data from big-endian to little-endian, you either convert the data in-place or you convert a copy of the data. As @antoinealb pointed out, CMP doesn't assume it can modify the data in-place, so it has to make a copy. It might be possible to add zero-copy reading without modding the API, but it probably isn't. There are a number of potential solutions: Add a zero-copy reader and a Pros: Minimal API changes necessary Add a Pros: Fast, and the semantics are clear I'm leaning towards the stream/buffer option because it's the best and the complexity can be managed pretty easily. It's also possible to handle endianness in a reasonable way at that point. Unfortunately I can't put a time estimate on this, and I'd like to do it myself rather than take a PR. Though if some intrepid soul wants to submit one and put up with what will certainly be a lot of heartless criticism and nitpicking, I won't stop them :) |
I am facing the same issue. Thanks a lot for your bringing in the enhancement. |
Thinking about this some more, I think the main issue is that the code uses Changing this is a subtle difference in behavior/semantics, but I think it's worth it: it's probably possible to nearly double CMP's speed by getting rid of this. The other advantage is that it's then possible to implement an "unpacked buffer" on top of CMP where you directly decode a MessagePack encoded buffer into a different buffer while only copying the data once. This way I don't need to split the API or modify |
As I see, currently to read a huge binary data, they need to be written to the buffer by reading function. What I would like to have is to get a pointer to memory-mapped binary instead of providing a buffer that will be eventually filled with binary data by reader function.
The text was updated successfully, but these errors were encountered: