-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Nit enhance 25 03 05 #2911
base: master
Are you sure you want to change the base?
Nit enhance 25 03 05 #2911
Conversation
Signed-off-by: SamYuan1990 <[email protected]>
Signed-off-by: SamYuan1990 <[email protected]>
Signed-off-by: SamYuan1990 <[email protected]>
Signed-off-by: SamYuan1990 <[email protected]>
Signed-off-by: SamYuan1990 <[email protected]>
Signed-off-by: SamYuan1990 <[email protected]>
the test passed on https://github.com/SamYuan1990/brpc/actions/runs/13688832022/job/38278130143?pr=33 let me test with 22.04. |
https://github.com/SamYuan1990/brpc/actions/runs/13689813245/job/38280860800?pr=34 tested my local github action, it works. |
ok, test passed, waiting for maintainer's review and feedback. |
LGTM |
Perhaps the original author wanted to use the lazy initialization mechanism to reduce memory usage. |
1.This way of initialization is much more common,uncontrolled use of global variables may cause dependency order problems(UB). |
Hi @zhangqiongyu , const std::string& AdaptiveMaxConcurrency::UNLIMITED() {
static const std::string s = "unlimited";
return s;
}
const std::string& AdaptiveMaxConcurrency::CONSTANT() {
static const std::string s = "constant";
return s;
} But when I realized that the function simply returns a constant string, I thought about making a broader change.
const std::string& AdaptiveMaxConcurrency::UNLIMITED() {
static const std::string s = "unlimited";
return s;
} |
Hi,It's a pleasure to have a friendly discussion with you. 2.Dependency order problems (UB). The snippet below is nothing todo with brpc, but what if someone wants to use this global variable in the future?
File2.cpp
3.About memory usage, lazy initialization is achieved by using functions to return static local variables, which are initialized only when needed, saving unnecessary resource overhead. In my usual projects, I prefer to use functions. In fact, I have done a lot of performance profiling, and this method has never become a performance bottleneck. Maybe what we are discussing is just some programming habits and trade-offs, but I don't think this will hinder the inclusion of PRs. |
What problem does this PR solve?
Issue Number:
n/A
Problem Summary:
A nit fix using const instead of static new, I am not C++ expert, but it seems we just have
static std::string*
with a fix value in previous implications of this PR. I suppose:as I am not C++ expert, I used another 3 commits to fix the compile issue.
What is changed and the side effects?
Changed:
Side effects:
Performance effects(性能影响):
I suppose those implements either previous impl for this PR or changes in this PR moves to compiler optimization.
I searched and learned through www, I suppose there only difference between the memory location for static(previous) and const(this PR), but compiler optimization is out of my knowledge, as previous adding additional function stack....
Breaking backward compatibility(向后兼容性):
Check List: