Support optimizations for native structs serialization when calling Pack()
When using the native struct C++ interface it would be nice if you could have a way of automatically enabling optimizations such as CreateSharedString and CreateVectorOfSortedStructs/Tables on calls to Pack(). Today there is no way to do this and as such complex/nested table structures created using the native C++ structures won't be stored as efficiently. These features would be particularly useful if you use a map-like structure to store data. Eg something like:
table Bool { value: bool; }
table Int { value: int; }
table Float { value: float; }
table Long { value: long; }
table String { value: string; }
table Ints { value: [int]; }
union DataUnion {
Bool,
Int,
Float,
Long,
String,
Ints,
Argument
}
table Argument {
name:string(key);
data:[DataUnion];
}
table ClassObjType {
name:string (key);
type:string;
arguments:[Argument];
}
There's likely a lot of room for optimization for the vectors and the strings in the Pack() case. In addition, unless one manually sorts vectors with keys you can't actually take advantage of the map-like lookups on read.
I guess the consensus was attributes would need to be added to fields like e.g. object_api: sorted or object_api: shared to hint at the code generator to use those alternative ways of constructing the data?
Yes, this would be cool to add.
Initial discussion: https://stackoverflow.com/questions/54436292/is-it-possible-to-optimize-flatbuffers-serialization-when-constructing-from-nati/54446116?noredirect=1#comment95709117_54446116
Related: https://github.com/google/flatbuffers/issues/5141
We already use native_ as a prefix for attributes related to the object API, so native_shared and native_sorted would probably be good.
Do we also want CreateVectorOfSharedStrings (or CreateSharedVectorOfStrings)?
Well, we currently don't even have an explicit CreateVectorOfSharedStrings function, so unless you or someone else has a use case for it, I'd say no for the moment.
This issue has been automatically marked as stale because it has not had activity for 1 year. It will be automatically closed if no further activity occurs. To keep it open, simply post a new comment. Maintainers will re-open on new activity. Thank you for your contributions.