MuseScore
MuseScore copied to clipboard
[MU4 Task] Optimize LayoutSystem::collectSystem
Task description
Resolves: https://github.com/musescore/MuseScore/issues/11392
This function is much slower in MU4 than in the previous versions of the application. The execution time of it (on my computer) when opening the large score from issue #11392:
For comparison, the MU3 version:
Main thread. Top 150 by sum time (total count: 13)
Function Call time Call count Sum time
Score::collectSystem 20.179 ms 648 13076.309 ms
Score::layoutSystemElements 13.687 ms 556 7609.958 ms
Score::update 2397.282 ms 3 7191.846 ms
Score::getNextMeasure 0.491 ms 5326 2615.643 ms
Ms::processLines 0.743 ms 3336 2479.808 ms
System::layoutSystem 0.531 ms 1112 590.605 ms
Thus, in MU3 it is called 2 times more often when opening the large score, but it wastes much less time. The problem is not only in LayoutSystem::collectSystem, but also in some subfunctions it calls: LayoutSystem::layoutSystemElements, LayoutMeasure::getNextMeasure, LayoutSystem::processLines, etc. They all perform much worse in MU4.
Our task is to find the slowest parts of the code and try to optimize them
@asattely @mike-spa I ported our profiler to MU3, so you can use my branch to measure performance in MU3. See: https://github.com/RomanPudashkin/MuseScore/commit/e62c0c21c8d5c6b1180345efafdecc03f42e44a7
@RomanPudashkin that's awesome, thanks!
Just for additional context: LayoutSystem::collectSystem()
is where 99% of all the engraving functions are called from. Anything we do in almost any part of the engraving engine will reflect on this method, so the task could also be renamed to "Optimize engraving engine".
Now, the engraving engine of MU4 is, in every possible way, more sophisticated than it was in MU3 so, to a certain extent, MU3 wasn't "faster", it was just "simpler". Still, MU4 probably shouldn't be twice as slow, so I think there is still good room for optimization (and it's great that we can use the profiler in MU3 now). We'll work on it!
I believe this issue is crashing the first release MU4 with large scores, especially when using the 'Continuous View'. I have a repeatable example, using the first release version Please read my bug post in the forum: https://musescore.org/en/node/337995