Improve stave access by caching index #27688
Draft
+34
−28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR attempts to cut down the time spent in
Staff::idx(called 3,745,816 times in the Beethoven) and relatedScorestaff functions. Previously, the index of aStaffin a score was determined by it's location in the Score'sm_stavesvector. Finding the index when given aStaff*required usingstd::find.We also need to be able to find a
Staff*given astaff_idx_t. This is used even more frequently (101,357,900 times in the Beethoven!) I have changed this to use[idx]rather than.at(idx), as we do our own bounds checking before this call. This appears to have increased performance in this function by 1.2% but I think this is firmly in the bounds of error.To maintain direct access to the
Staff*pointer by index and allow direct access to the index byStaff*pointer, I have simply added astaff_idx_tmember toStaff. This is straightforward to keep track of as there are only 3 methods which modify them_stavesvariable -Score::appendStaff,Score::insertStaffandScore::removeStaff.Overall, the improvements are slim. There is no significant change in total score layout, but
Staff::idxhas been sped up by 21%.