-
Notifications
You must be signed in to change notification settings - Fork 4
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
Prost support (i.e. #[global_allocator] or arena allocator) #13
Comments
I'd like to check a few things:
Those are the "commonly given reasons" for not wanting a heap, but to be fair: (a) other methods of dynamic memory management like a fixed capacity memory pool (b) other methods of dynamic memory management also incur performance overhead. (c) A memory pool hands out fixed-size memory blocks that sit next to each other (d) there are heap allocators with constant-time So, not using heap allocator does not remove these 4 issues. As long as you I think a more relevant question here would be if you think a general-purpose
The I have not looked at what kind of code prost can generate but if we can make it I'm thinking of structs like this: // `'self` is made-up syntax that means self-referential
struct Packet {
// a chunk of memory
blob: alloc::Box<[u8]>,
// fields specified in the .proto file
id: u32,
some_bytes: &'self mut [u8],
// map allocated in contiguous memory (i.e. not in a tree)
some_map: IndexMap<'self, u8, u8>,
} All fields that would normally heap-allocated are allocated in the
In any case, I think we should start with plain |
This sounds good to me (however I believe Longer term: I think all of the data structures we'd want to use for Protobuf "APDUs" could be represented with As for our longer term needs for |
There's one big reason why Protocol Buffers may be a bad fit for our needs: the schema language has no way to express length information about "bytes", e.g. fixed-sized bytestrings or bytestrings with a maximum length, which makes it difficult to describe something like an "APDU" which maps to fixed-sized e.g. In the past I've gone down the road of making Unfortunately, while An alternative is to use a similar schema-driven TLV format, but one designed to work out-of-the-box in heapless environments. I have been toying around with such a format. I think it'd be ok to use a format like this purely for serialization (e.g. having domain types separate from the encoding objects), with |
While there's been some upstream movement on |
We'd like to use Protocol Buffers as the serialization format for our "APDUs".
Prost provides a pure Rust implementation of the format, and Prost v0.6 upgraded to
bytes
v0.5, which added#![no_std]
+liballoc
support. There's an open PR to add#![no_std]
+liballoc
to Prost as well:https://github.com/danburkert/prost/pull/215
If that lands, the simplest option for supporting Prost would be to use
liballoc
and define a#[global_allocator]
. However,bytes
was also refactored to (but does not yet fully support / expose) customizable vtables as the backing storage:tokio-rs/bytes#298
This should allow it to support to support e.g. arena allocators. Since we're trying to support a simple APDU-like RPC protocol (possibly with interrupts and fixed-N concurrent requests), we could probably get by with a very simple arena allocator like [
bumpalo
](https://github.com/fitzgen/bumpalo (although looks likebumpalo
needsliballoc
too), since we'd always reclaim all of the allocated memory when a request completes, which seems like it might be a better fit for an RTFM environment (especially if we did eventually want to hit certain realtime deadlines).The text was updated successfully, but these errors were encountered: