-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
add SetStringByArray(..., const char *, size_t) method in Reflection #6399
Comments
Unfortunately I don't think there's any easy way to do this. Internally messages store |
@acozzette bool foo(const char *buf, size_t size,...) {
...
std::string temp(buf, size); // actually, we don't need to create a temporary std::string here, if we have
// some method like SetStringByArray(..., buf, size);
reflection->SetString(...., temp);
...
} the original case comes from the following code, and I measured it in a 8MB bytes case. the
|
If the string is passed by value or by rvalue reference then we can eliminate one of the two copies. The user can create the string and then it can be moved directly into place. |
Adding an overloaded |
copy that. when will this feature be added to the master? |
I'm afraid I don't have time to work on it, but if you want to try implementing it yourself then feel free to send me a pull request. |
solution:
|
What language does this apply to?
cxx and other binding languages such as python's cpp_implenentation
Describe the problem you are trying to solve.
the Reflection class in message.h only has
SetString(..., const std::string &value)
interface. in some cases, we just have raw buffer (char * and size), to call the SetString method, we have to construct/memcpy/deconstruct a std::string. But in some time-sensitive case, this consumes much, especially when the the bytes is large enough (eg. 8MB), which will cause large amount of page-faults.Describe the solution you'd like
Add
SetStringByArray(..., const char *, size_t )
interface, and call it when necessorily.Describe alternatives you've considered
even in protobuf, construct 8MB bytes(std::string) will cause large amount of page-fault, this will slow down much. is it possible to setup an allocator for the protobuf. I did not seen such method.
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: