Skip to content

Conversation

@miiizen
Copy link
Contributor

@miiizen miiizen commented Apr 14, 2025

This PR attempts to cut down the time spent in Staff::idx (called 3,745,816 times in the Beethoven) and related Score staff functions. Previously, the index of a Staff in a score was determined by it's location in the Score's m_staves vector. Finding the index when given a Staff* required using std::find.

We also need to be able to find a Staff* given a staff_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 by Staff* pointer, I have simply added a staff_idx_t member to Staff. This is straightforward to keep track of as there are only 3 methods which modify the m_staves variable - Score::appendStaff, Score::insertStaff and Score::removeStaff.

Overall, the improvements are slim. There is no significant change in total score layout, but Staff::idx has been sped up by 21%.

@miiizen miiizen marked this pull request as draft April 14, 2025 14:19
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.

1 participant