I want to make it easy and safe for users of capnproto-rust to read messages from unaligned buffers without copying. (See this github issue <https://github.com/capnproto/capnproto-rust/issues/101>.)
Currently, a user must pass their unaligned buffer through unsafe fn bytes_to_words() <https://github.com/capnproto/capnproto-rust/blob/d1988731887b2bbb0ccb35c68b9292d98f317a48/capnp/src/lib.rs#L82-L88>, asserting that they believe their hardware to be okay with unaligned reads. In other words, we require that the user understand some tricky low-level processor details, and that the user preclude their software from running on many platforms. (With libraries like sqlite, zmq, redis, and many others, there simply is no way to request that a buffer be aligned -- you are just given an array of bytes. You can copy the bytes into an aligned buffer, but that has a performance cost and a complexity cost (who owns the new buffer?).) I believe that it would be better for capnproto-rust to work natively on unaligned buffers. In fact, I have a work-in-progress branch that achieves this, essentially by changing a bunch of direct memory accesses into tiny memcpy() calls. This c++ godbolt snippe <https://godbolt.org/z/Wki7uy>t captures the main idea, and shows that, on x86_64 at least, the extra indirection gets optimized away completely. Indeed, my performance measurements so far support the hypothesis that there will be no performance cost in the x86_64 case. For processors that don't support unaligned access, the extra copy will still be there (e.g. https://godbolt.org/z/qgsGMT), but I hypothesize that it will be fast. All in all, this change seems to me like a big usability win. So I'm wondering: have I missed anything in the above analysis? Are there good reasons I shouldn't make the change? - David -- You received this message because you are subscribed to the Google Groups "Cap'n Proto" group. To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/CABR6rW-JpiJntc0i7O4cVywzfvd2YnVp89BgYeJp_Gwzoc_Edg%40mail.gmail.com.