With stats getting close to 4500, we're soon going to run into limits with the iteration algorithm as the total stats will be larger than 10,000. This also gets progressively slower as stats get higher. I thought about the approach git's bisect method uses and had a go with it here: basic binary search with a guard on both outcomes, using the stat as input. There are a few alternatives but I felt this was the simplest to implement, and it's about 20x faster than the current iterator. In terms of loops, the test added in this PR runs 6700 iterations, and the bisector runs 34 iterations.
Not really sure this is a great implementation, assigned to a const felt right at the time until I needed to switch stats and control required special handling. Happy to answer any questions or if you've got better ideas on any of it.
I recommend reading the diff in split diff mode instead of unified, it helps a lot.
With stats getting close to 4500, we're soon going to run into limits with the iteration algorithm as the total stats will be larger than 10,000. This also gets progressively slower as stats get higher. I thought about the approach git's bisect method uses and had a go with it here: basic binary search with a guard on both outcomes, using the stat as input. There are a few alternatives but I felt this was the simplest to implement, and it's about 20x faster than the current iterator. In terms of loops, the test added in this PR runs 6700 iterations, and the bisector runs 34 iterations.
Not really sure this is a great implementation, assigned to a const felt right at the time until I needed to switch stats and control required special handling. Happy to answer any questions or if you've got better ideas on any of it.
I recommend reading the diff in split diff mode instead of unified, it helps a lot.