-
Notifications
You must be signed in to change notification settings - Fork 406
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
Refactor fractionSum for simplicity and performance #1674
Conversation
Can you explain how you are sure that your answer produces the exact same result as the previous code? I see that you are doing a lot of floating point arithmetic and then a I can immediately find errors that didn't exist before:
Old: New:
If the rebuttal is "well, we'll never have so many time signatures to add to have this problem" then we'll never realize any performance improvements with this. The general rule is - never cast a fraction to a float. It will always have some error on some OS that will never be detected. This is why fraction arithmetic is slower than this method, it's because it never has to worry about rounding errors. |
Thanks for contributing though. I appreciate it. If doing performance-related boosts, be sure to focus attention on parts of the system that we're seeing performance problems on; I don't think that fractionSum is one of them, as it is very rarely called. For PRs, best to make a number of small ones that each fix or improve one thing, unless they depend on each other somehow. |
Safer speedups are included in #1631 |
Understood and I appreciate the feedback. I'll submit more straight-forward pr when I have time. |
Important: I wasn't able to get the current version of the master branch to pass the tests even without any changes (perhaps I was doing something wrong). So this PR was made on top of the fix-mypy-error branch. That means that accepting this PR will also merge the fix-mypy-error branch changes.
About the actual changes I made, they're all in music21/meter/tools.py -> fractionSum. fractionSum is refactored to be easier to read and more performant. The same results are returned in the same format, but there's between a 0% and 50% decrease in runtime depending on the case. I didn't measure memory usage but it should also be lower since fewer iterables are created.
If this sort of PR is wanted, I have about 10 small changes (even smaller than this one) ready to go that I could also contribute. If so, is it better to commit each one individually, or one altogether? I dove into python sets and other basic structures and wanted to apply that knowledge in a practical way, and that is common thread in the changes.