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
implement FlatArrayMessageReader #25
Comments
Those allocations are indeed probably the most expensive part of what you're doing. It should be possible to avoid them, although I admit that the interfaces I've provided don't make it obvious how to do so. To avoid any allocations, you want to use a You should write your messages using For this to work, you'll probably need to be able convert between |
Thanks for the pointers. Sounds complicated. |
The allocations are not required by the protocol; they are required because we need a place to put the data.
We could avoid some allocation by implementing a |
I imagine it will be possible to avoid the allocation by using a stack-allocated array, eh? ScratchSpaceMessageReader looks like what we need! Should I leave this request open till then? |
Yes. Leave this open until we've got something working for you. :) |
Isn't one of the promises of Cap'n Proto protocol that one can mmap a message and never lift a finger at deserialization, because the bytes are in the needed format already? (There's a lot about it on https://capnproto.org/: no encoding/decoding step, mmap, random access). I take it the Rust version doesn't really implement that part? |
If you have a The part that's missing right now in capnproto-rust is something that takes a |
Yup, I'd like to try. Will check the |
Implemented in userspace:
On a very small message I see a speedup from 243 ns/iter to 160 ns/iter. |
BTW, I've been thinking how one would go about creating an object, e.g. FlatArrayMessageReader, instead of using the visitor. Problem is, I'd like to keep the one-segment path and small-number-of-segments path to have different stack requirements, e.g. just Am I missing something? Would the P.S. One obvious approach is to teach capnproto-rust to use some special type instead of |
Hm. Your implementation and comments got me thinking. Maybe we should change
And it could be used like this:
This would avoid unnecessary allocations and retain maximal flexibility, but it might be somewhat cumbersome to use. Thoughts? |
I think the lifetimes might not quite work out in the proposal I sketched in the last comment. But it seems like there ought to be some way to fix that... |
Right, that should work!
Will try to implement it later.
|
My recent changes in b1c54c9 should make this significantly easier. I think that it's now straightforward to implement something like this: fn read_message_from_flat_array<'a>(&'a [Word]) -> message::Reader<message::SegmentArray<'a>> {
// ...
} |
It's much nicer! I'm using it the old closure-way still:
Should look into spawning the Reader. Thanks. |
I've pushed some changes that include a new function |
Closing, because I think the problems brought up here have long since been solved. @ArtemGr, please feel free to open a new issue if you are still having problems. |
NP! Sorry I wasn't able to make a |
Hi! In http://youtu.be/A65w-qoyTYg?t=14m57s you say that reading from a Cap'n Proto message is comparable to a struct field access, or at least I've got that impression from your talk.
Now, testing it with a simple benchmark
which uses the following schema
shows that reading from a Cap'n Proto message is much more expensive than a struct access.
I get
3931 ns/iter
from it.(In fact, the LMDB database where I keep this value is faster at returning it from the database (
616 ns/iter
!) than Cap'n Proto is at decoding it).Theoretically I'd imagine that the decoding should involve just some memory accesses, but examining the
new_reader
code I see a couple of Vec allocations there.So,
Am I doing something wrong?
Is it a state of the art Cap'n Proto performance or will it be improved?
The text was updated successfully, but these errors were encountered: