-
Notifications
You must be signed in to change notification settings - Fork 121
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
Memory usage using cista::variant #121
Comments
Generally type Note that this would also be the case if you would use a raw C I think in case you want to transmit a large number of messages in one chunk of data, you could try data oriented programming - storing something like this:
If you want even more performance, the only way would be to do a custom protocol sending one byte indicating the message type, the message size, and then followed by the message. Another way would be to make a |
Can you propose a way how |
Would be a custom serializer/deserializer a solution? |
Cista uses the same format for serialization as it uses for in-memory use at the program runtime. All Cista data structures can be used as a replacement for the corresponding I'm not sure, if a custom serializer would work - possibly. I'm pretty sure, this would lead to the data being Maybe you can experiment and post your findings here? I would be curious how this could work. |
What I mean is not Object Oriented Programming (OOP) but Data Oriented Programming. Maybe the order could be indicated by an additional field per message. I think the zero-copy property of Cista makes it impossible to have a different size for What you really need is probably a format |
Another hint would be maybe to implement this for your variant: https://github.com/felixguendling/cista/blob/master/include/cista/serialized_size.h I added this on the request in another issue here. So it looks like someone is doing stuff like this. I just don't know how 🤣 |
Thanks for support. As you mention, the simplest way is to serialize message type as byte then message and so on. serialized_size.h looks interesting. I was thinking about some space optimization involving variants, it's just an idea :) |
BTW I would like to use a binary API based on Cista than an API based on JSON. |
I think, this could work. But implementing this will take some time. However, due to alignment requirements in the data vector keeping the variants, there would still be some waste compared to what you could do manually. For example if you had a
I don't exactly understand what you mean with this? Can you make an example (input -> what it does -> output)? At the moment, it's not possible in C++ to get the names of fields in structs, so there cannot be an automatic conversion from C++ struct to JSON without additional info. With C++20 it's possible to have something like |
For 1. indeed there is a trade-off between the flexibility of variants and compactness. If the variant objects will have more than 8 bytes, I think the space efficiency will be decent. Maybe an option would be to group variant objects by their size at construction time when initialization list is used in order to improve space efficiency. For 2. I'm trying to create a flexible and minimalist RPC binary protocol in contrast with many JSON web based APIs which are IMO not time and space efficient compared to Cista. Initially I wanted to use Cista to serialize/deserialize both RPC primitives (call, call result, notification, etc.) and data transferred (function parameters and function results). The best way seems now to implement a custom serialization for RPC primitives and to use Cista only for data transferred. |
For performance reasons I would not use meta information for RPC for every transaction as it is in JSON. A set of discovery functions could provide meta information about API. |
Sounds like a great idea. I think the variant_vector could also be useful for other use cases.
For this, the information about the field names needs to be available, which it currently is not. So still a wrapper |
I'm trying to use cista for a protocol with messages (structures) having between 8 and 88 bytes. I used cista::offset::vector<cista::variant<msg1, msg2, etc.>>.
Having a vector containing 10 messages of 8 bytes, what would be the memory used? I guess the serialized buffer will have approximately the same size.
The text was updated successfully, but these errors were encountered: