Skip to content
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

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

handrok
Copy link
Contributor

@handrok handrok commented Jan 2, 2025

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 the StaffName constructor calls TextBase::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.

@handrok handrok requested a review from RomanPudashkin January 2, 2025 15:00
@handrok handrok self-assigned this Jan 2, 2025
Comment on lines +857 to +864
for (String name : nameList) {
if (name.isEmpty()) {
continue;
}

if (!caseSensitive) {
name = name.toLower();
}
Copy link
Contributor

@shoogle shoogle Jan 3, 2025

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;
Copy link
Contributor

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();

Copy link
Contributor Author

@handrok handrok Jan 3, 2025

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

Copy link
Contributor Author

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.

Copy link
Contributor

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!

@handrok handrok merged commit a42b834 into musescore:master Jan 3, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants