-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
[Core] Codestyle improvements to math types #88467
Conversation
Found a few more cases that I'll add tomorrow |
I wonder if explicitly defining |
For primitive types, it doesn't affect performance. It's purely about code style (it avoids accidentally reassigning a function parameter). |
What is the reasoning behind passing EDIT: Ah, I see, sorry, I see that this is what you were correcting. 😁 Blimey 😨 there's some of this in 3.x, we should correct it there too. You would hope the compiler would optimize past this in release, but I don't know what the guarantees require. And for debug who knows. To quote, this is the danger:
|
Nominally a primitive compiler might be helped by But a decent optimizing compiler would use some form of SSA analysis anyway which would handle detecting and collapsing changes to the variables anyway, though Will push additional changes momentarily Edit: No changes to compile time, it's all within error margins, both with and without these changes I get between 2:40-2:50 per build, so it just affects the code style (and makes it easier to read IMO, beyond just aligning with our style) |
6eea1ae
to
73c1e86
Compare
The point about passing by reference is true! Didn't think of that, it is a strong reason to not pass simple types, will do a further sweep for such later and look at 3.x too! I'd lean on using references for complex types but it's something to discuss for the future, can do some benchmarking later as well, I think the improvement by passing in a register (when passing a reference) is greater than the possible drawback of mutation issues (with possible exceptions for certain types of 64 bit builds, in a 64 bit build a But absolutely worth looking into for simple types, will do a sweep later today, thank you for these notes! I'd assume a decent compiler would handle this, but no harm in improving code style and helping at the same time, will benchmark a release build later today with the current changes to see if it matters on that end |
Rule of thumb I've usually seen used:
Also if it is non-pod and has complex copy constructors etc then by reference becomes more favourable so you can avoid these. Compilers also have rules about strict aliasing etc to help prevent yourself shooting yourself in the foot, but imo it helps to explicitly tell it what you intend it to do. Also compilers are usually very smart about working out your intention (and will often use a faster way to achieve same), but sometimes they are constrained by rules for non-obvious situations. |
73c1e86
to
d2292dd
Compare
Prepared a 3.x version and will open a PR once a decision has been made on this PR (it's smaller in scope but has a few Also tested a release build on mingw (with disable_3d as it compiles a bit faster just for the benchmarking) and there was no discernable difference between this and |
d2292dd
to
ff8c978
Compare
ff8c978
to
a497a5c
Compare
Thanks! |
Thank you! |
General style improvements to bring these classes into the code style standards
Removing unnecessary
const
and addingp_
andr_
prefixes when needed