Skip to content
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

Replaced utstring with std::string #1009

Merged
merged 1 commit into from
Sep 25, 2017

Conversation

pschafhalter
Copy link
Contributor

No description provided.

@AmplabJenkins
Copy link

Merged build finished. Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/1921/
Test PASSed.

@@ -1451,7 +1444,7 @@ void process_object_notification(event_loop *loop,
* into two structs, one for workers and one for other plasma managers. */
ClientConnection *ClientConnection_init(PlasmaManagerState *state,
int client_sock,
char *client_key) {
const char *client_key) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to go further and make client_key a std::string as well? And then to make conn->ip_addr_port a std::string? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense. I'll make those updates as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact client_key should be a const std::string& :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like ClientConnection is still using the UT_hash data structure which can't use std::string as a key. I'll need to update that to an ordered map as well. Would you prefer I do that in a separate PR or can I make these changes in here as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping PRs as small as possible is best, why don't you make a separate one?

@concretevitamin
Copy link
Contributor

Side note: are the changed functions on a performance-critical path? Just wondering if string concat. should avoid the + operator.

@pcmoritz pcmoritz merged commit 6e9657e into ray-project:master Sep 25, 2017
@robertnishihara
Copy link
Collaborator

robertnishihara commented Sep 25, 2017

@concretevitamin Yeah, that's a really good point.. get_manager_connection is called very frequently, so this could be an issue.

@pschafhalter
Copy link
Contributor Author

@concretevitamin @robertnishihara is the expected length of the final string known? Calling reserve() could reduce overhead from concatenation.

Otherwise, something like std::ostringstream could also speed up concatenation.

@mehrdadn
Copy link
Contributor

mehrdadn commented Sep 26, 2017

@concretevitamin @pschafhalter [cc @robertnishihara]
Note that it may be risky trying to spend time to make that kind of optimization without profiling. For example:

  • Small-string optimization in C++ could in fact render this bottleneck a non-issue, depending on your standard library. The longest [IPv4] string here would be 21 characters (111.111.111.111:11111) and on a 64-bit system libc++ has stack space for 22 chars, though libstdc++ has 15). And the latter would still optimize out allocations for common cases such as 192.168.1.255:, reducing it to 1 actual heap allocation to construct the full address.
  • If concatenation of a fixed number of strings truly does become a bottleneck, you will most likely have to remove all string instantiations (e.g. sprintf to the stack) entirely, not merely remove the concatenations.
  • If you use something like std::stringstream, it will likely be slower.
  • If you use sprintf, you'll have to worry about stack buffer overflows.
  • Depending on your standard library, std::to_string in fact may end up being a bottleneck in itself, due to localization issues (locales/facets/etc. often end up being extremely slow).

Generally, I would avoid spending time on such optimizations unless (a) the optimized version isn't too much harder to write (& read) than the original version, and (b) unless it is completely obvious that the optimized version will lack the bottlenecks. Otherwise, it's best to just wait until a profiler pinpoints potential hotspots.

@robertnishihara
Copy link
Collaborator

Thanks a lot @mehrdadn, that's super informative! And I love that the takeaway is that I don't have to do anything right now :)

@pschafhalter pschafhalter deleted the ut_string_to_std_string branch September 26, 2017 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants