Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
OpenTelemetry API Review Feedback #3687
OpenTelemetry API Review Feedback #3687
Changes from 2 commits
6512cb5
3e706d8
83ffed9
e8c474e
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason or benefit of using stringstream here for building up the string, rather than just appending/concatenating regular std::string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally there were 4 elements being concatenated, one of which was an integer.
stringstream
was the best solution for that case.Now it's not required but realistically the difference in complexity is probably negligible (adding two strings creates two temporary std::string objects and then assigns their concatenation to a 3rd, using stringstream allocates a buffer, then reallocates the buffer and then creates a std::string from that buffer - probably identical performance characteristics).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
It stood out to me because I recall @BillyONeal or @CaseyCarter mention a while back to only use stringstream for formatting and not for string building scenarios like this. But I might be misremembering the detail (or reason).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that
std::string
does not have the C# usual "append becomes N^2" issue:const std::string
~= C#string
,std::string
~= C#StringBuilder
.stringstream
is less efficient in general than usingstd::string::append
orstd::string::push_back
directly (where possible to do so). But you can't format numbers or things like that with it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this example, the two
<<
s are 0 or 1 allocation each (depending on length), then thestr()
is always an extra allocation. If this were insteadauto ss = "HTTP " + request.GetMethod().ToString();
, there is 0 or 1 allocation for the+
and no second allocation on use.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Note that there's no temporary string constructed for the
"HTTP "
, you call this operator+, assumingToString
returns a prvalue:https://github.com/microsoft/STL/blob/17fde2cbab6e8724d81c9555237c9a623d7fb954/stl/inc/xstring#L5053-L5057
)