Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpc: optimize tuple deserialization when the types are default-constr…
…uctible rpc deserialization cannot assume the types that make up the return tuple are default-constructuble, and cannot deserialize directly into the tuple constructor, so it is forced to construct a default-constructible tuple formed by wrapping every T with std::optional, deserializing into that, and then converting the temporary tuple into the return tuple by calling std::optional::value() for each element. This wrapping and unwrapping is wasteful, and while the compiler could theoretically fix everything up, in practice it does not. We notice that the first value can in fact be deserialized in the tuple constructor arguments, since there's no ordering problem for it. So we remove the std::optional wrapper for it unconditionally. For the rest of the elements, we wrap them with std::optional only if they are not default constructible. If they are, we leave them unchanged. Finally, the unwrapping process calls std::optional::value if the type was wrapped; and if none of the types were wrapped (which ought to be the common case), we return the temporary tuple without any unwrapping, reducing data movement considerably. The optimization is written in a way to also include the previous optimization when the tuple size was <= 1. Testing on ScyllaDB's messaging_service.o, we see another reduction in .text size: text data bss dec hex filename 6758116 48 236 6758400 672000 messaging_service.o.before 6741352 48 236 6741636 66de84 messaging_service.o.after About 17kB.
- Loading branch information