You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
clean up unnecessary std::string() in Envoy #11318
Hey, @alyssawilk I am not able to understand which std:: strings are not required. Could you tell me how do I decide which ones to remove and which ones to keep?
Expounding on the above, std::string(x) creates a new string object by copying the contents of x. That's great and necessary if the string needs to outlive x, but if not then the copy is just wasting CPU time. If you can replace std::string(x) with just x and all the tests still pass, then that conversion probably wasn't required! You might come across a few places where a string_view is converted to call a method that takes a const std::string&, but in that case we should make the method take a string_view instead since it's the moral equivalent and more flexible.
I'd group somewhat arbitrarily to try to manage PR sizes - if there's a root directory with ~50 you can do the whole thing, where sometimes you might need to limit to one type of extension depending on how many changes there are. Maybe kick one off and see how it goes, and iterate from there?
Alright! Quick question, is there any way to speed up the tests? I've fired up a VM with 4 vCPUs and 32 gigs of RAM for this but the tests still take more than hours to get done.
yeah, 4 CPUs is going to take a while. :-(
I find that on slow machines kicking off an overnight build, then doing incremental builds the next day helps. Also if you're mainly checking compile/asan you can just test //test/path/to/code/changed rather than the whole suite, then rely on CI for the full pass.
Activity
yashwant121 commentedon Jun 3, 2020
Hi @alyssawilk, I would like to take this issue.
alyssawilk commentedon Jun 3, 2020
Thanks! Tossing it your way :-)
PranshuSrivastava commentedon May 14, 2021
Hey, @alyssawilk I would like to take this issue.
PranshuSrivastava commentedon May 21, 2021
Hey, @alyssawilk I am not able to understand which std:: strings are not required. Could you tell me how do I decide which ones to remove and which ones to keep?
alyssawilk commentedon May 24, 2021
grep -r std::string( source/* gets you potential call sites, but you'd have to figure out which results are unnecessary
akonradi commentedon Jun 16, 2021
Expounding on the above,
std::string(x)creates a new string object by copying the contents of x. That's great and necessary if the string needs to outlivex, but if not then the copy is just wasting CPU time. If you can replacestd::string(x)with justxand all the tests still pass, then that conversion probably wasn't required! You might come across a few places where astring_viewis converted to call a method that takes aconst std::string&, but in that case we should make the method take a string_view instead since it's the moral equivalent and more flexible.ShubhamPalriwala commentedon Jul 14, 2021
Hey @alyssawilk, I have understood the issue and would like to work on this! Just wanted to ask, will one heavy commit be fine?
alyssawilk commentedon Jul 14, 2021
I'm not sure how many there are. If there are 20-30 cases sure, if it's more like 200 then splitting it up into a few PRs would be super helpful :-)
ShubhamPalriwala commentedon Jul 14, 2021
There are 1352 instances of this so I have to check each one of them. 😩
Should I make different PRs for each directory then?
alyssawilk commentedon Jul 14, 2021
I'd group somewhat arbitrarily to try to manage PR sizes - if there's a root directory with ~50 you can do the whole thing, where sometimes you might need to limit to one type of extension depending on how many changes there are. Maybe kick one off and see how it goes, and iterate from there?
ShubhamPalriwala commentedon Jul 15, 2021
Alright! Quick question, is there any way to speed up the tests? I've fired up a VM with 4 vCPUs and 32 gigs of RAM for this but the tests still take more than hours to get done.
Help here would really really be great!
alyssawilk commentedon Jul 15, 2021
yeah, 4 CPUs is going to take a while. :-(
I find that on slow machines kicking off an overnight build, then doing incremental builds the next day helps. Also if you're mainly checking compile/asan you can just test //test/path/to/code/changed rather than the whole suite, then rely on CI for the full pass.
annanya-mathur commentedon Aug 28, 2021
I would like to take this issue
cleanup: replace std::string to absl::string (#19032)
TTashev commentedon Jun 19, 2022
Hello, anybody still working on this, I would like to participate.
alyssawilk commentedon Jun 21, 2022
Feel free to send out PRs!
Akshayshahi900 commentedon Jun 30, 2026
Hi, I'd like to work on this. I'll grep the codebase for remaining unnecessary std::string() usages and submit a PR.