-
-
Notifications
You must be signed in to change notification settings - Fork 8.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
UI: replace QString() with QStringLiteral() for better performance #11454
base: master
Are you sure you want to change the base?
Conversation
Can you please provide more information on what situations you were seeing a performance issue that lead to this change? Also what testing was done to show this had improved performance? |
Qt Documentation says
From my perspective, the actual difference is not apparent (slightly faster) |
The key part here is "data known at compile time". Most of these instances have |
Function signatures doesn't need to change, as the generated type of |
Pretty much all of these are cold paths rather than hot paths. I don't necessarily disagree with doing it but I'm just noting that it's not really all that significant to have occasional allocations in a cold path. Not sure if it's worth the commit but I don't particularly feel strongly about it one way or the other. |
I think the important distinction of this PR is to use It would be similar to storing a template literal like "My String with argument %1" as a Some more explanation about its benefits can be found here: https://woboq.com/blog/qstringliteral.html |
I compared the time of Below is the measurement with ~1000 calls of
Also the PR needs to follow the commit guideline. The modification should be separated for each module such as UI, obs-vst, etc. and the commit title should start with the module name. |
When making code refactoring PR, each module should be made separately? |
Yes, at the very least for each "part" of the program, i.e. separate commits for I think it's important to point out that using
So in the same way we use Any performance benefits are just icing on the cake. |
a9c8cde
to
fc46b2a
Compare
I just shrank the scope of this PR to UI only |
I'll defer to Pat on this one. |
@Lain-B Any progress on this PR? :) |
Conceptually I'm fine with the replacement, but I haven't had time to fully review it locally yet (which is mainly for me to give a proper approval). Pending any weirdness I might find it can probably be merged after the holidays (as we just released a new version, need to monitor its progress and then probably want to spend some time with friends and family). |
This PR only addresses explicit casts from const char to QString. There are tons and tons of implicit casts in the codebase that have the same problems as Pat outlined above, just hidden away from the developers by implicit casting. If people are pedantic enough to merge this PR, I would suggest also considering setting *As a warning, I do mean tons and tons. In my case the compiler stopped due to too many errors after about half a file. I personally do not think it's worth doing that, but I think the same about this PR (they're the same thing, just explicit vs implicit). |
Description
QStringLiteral()
provides better performance thanQString()
when constructing QString objects.Motivation and Context
QStringLiteral()
, which makes constructing QString objects from string literals more efficient.How Has This Been Tested?
Types of changes
Performance enhancement (non-breaking change which improves efficiency)
Code cleanup (non-breaking change which makes code smaller or more readable)
Checklist: