-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
improved score openning speed by optimisation the searchTemplateForInstrNameList function #25971
Conversation
…strNameList function
for (String name : nameList) { | ||
if (name.isEmpty()) { | ||
continue; | ||
} | ||
|
||
if (!caseSensitive) { | ||
name = name.toLower(); | ||
} |
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.
This might help too by avoiding copying strings unnecessarily:
for (const String& name : nameList) {
if (name.isEmpty()) {
continue;
}
const String& normalizedName = caseSensitive ? name : name.toLower();
StaffName instrName(normalizedName);
continue; | ||
} | ||
|
||
String trackName = it->trackName; |
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.
Avoiding another string copy:
const String& trackName = caseSensitive ? it->trackName : it->trackName.toLower();
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.
String trackName = it->trackName;
muse::String is designed like QString from QT. It has move semantic. Copy of muse::String object doesn't lead to allocate memory. Only just pointer to shared memory is copied. Allocating memory is happening only if muse::String data is changed.
const String& trackName = it->trackName.toLower();
that code doesn't improve performance. memory is allocated inside of toLower()
method. And toLower()
creates local variable and return it. So memory was allocated anyway and one copy of muse::String
object is happened. But as I said copying of muse::String
is not a big problem. It has move semantic and copying muse::String
is not much bigger then using of reference. sizeof(muse::String) is 16 bytes which is double of sizeof of reference. I think it is not a big deal. Instead of copy 8 bytes I copy 16 bytes here. And increase pointer count inside muse::String
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.
But I cant change it if you insist.
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.
No, I'm happy with it. Thanks for the explanation!
It depends on the score and your machine. In my case, 10% of the time spent opening the score occurs inside the
searchTemplateForInstrNameList
function. The bottleneck here is the creation of StaffName(instrName) for each iteration of the loop, because theStaffName
constructor callsTextBase::validateText
, which performs a lot of work. Simply changing the order of three loops gave me a 10% boost in score opening time, as I tested.