-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
Draw horizontal lines and labels in the editor performance monitors #39719
Draw horizontal lines and labels in the editor performance monitors #39719
Conversation
76510bd
to
2d31174
Compare
constexpr int margin = 3; | ||
constexpr int point_sep = 5; |
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.
Why are these constexpr
and not just const
?
Also, we should likely start a broader discussion on whether this kind of micro optimizations actually make a difference at all. If yes, we should use them consistently in new code. If not, we should probably not refactor existing code to use 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.
I changed them to use const
. And yes, we should probably look at using constexpr
instead of symbolic #define
s in the future.
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.
I mean, does using const
for local variables really make a performance difference? Or are compilers clever enough to optimize all this code already and us doing it manually is overkill? I think this should be benchmarked before continuing to make all local variables const
.
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.
I think it's more about code readability than performance. I don't think const
local variables make any difference for compiler optimization. However, with const
, it's guaranteed the variable isn't being reassigned below. This can make the code significantly easier to read and less error-prone. I've seen lots of old code in Godot where variables are being reassigned for no good reason, and that makes it harder to reason about the code.
For this reason, using const
should also make online code reviews a bit easier 🙂
The only case where I consider const
to be overkill is in function parameters for primitive types (like the ISO C++ Core Guidelines say).
This partially addresses godotengine/godot-proposals#1014.
2d31174
to
a593786
Compare
Thanks! |
Cherry-picked for 3.2.2. |
This partially addresses godotengine/godot-proposals#1014.
Preview