-
-
Notifications
You must be signed in to change notification settings - Fork 279
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
Pitch.CalculateTransposeHalfTone performance improvements #1374
Conversation
…es to EngravingRules.AutoGenerateMultipleRestMeasuresFromRestMeasures
Nice! We just need to check if the result is the same, I'll run the visual regression tests. |
Also, I don't think this function is used very often, so the performance impact will probably be hardly noticable. If we usually spend 100 nanoseconds on all of the function calls, and now only 1 nanosecond, it will hardly be noticable. (we probably spend more than 100 nanoseconds, but just theoretically speaking) I'll also quickly check how often this function is used and how much time it uses. |
on my fork i put a console.log |
In any case, you must do all the necessary checks! |
I didn't say it's not used, I said it's not used a lot, and not much time is spent in it ;) but I'll check it myself as well. |
This is right! The actual code of your function is very understandable, this facilitates optimizations! In any case, think back to my test, if I start from halftone values from -1000000 to +1000000 (values that don't exist in music) and considering that the current routine is based on while loops to increase the octaves, it is obvious that the my routine is faster. |
Indeed, I got carried away by enthusiasm; now the values are completely different. In the following message, I will write my test. Test 1: consistency between results |
|
... and with >=24 .. <24 range Test 1: consistency between results ...please and for the sake of clarity, leave your routine untouched... :D |
@ammatwain So in the realistic usecases of -128 to +128 halftones transposition, your method is 43.75% faster, and for more common cases of -24 to +24 halftones, it's the same speed, correct? |
The function comment could be something like this?
|
Closing, as I've added the alternative method in a comment in commit e6cbba6, and the method is not faster for realistic use cases. Still, thanks for the investigation, it could have been a performance improvement if the realistic input data range wasn't limited, and it's an interesting rewrite of the loops into a one-line mathematical statement / code line. By the way, you've named the TransposeCalculator class file TransportCalculator and addded it as a new file, but it's not relevant anymore now. |
Simon, thank you for your response. You did well to keep the original method since it performs its job excellently. Regarding the commit containing the "TransportCalculator" class, I apologize; it was due to my lack of experience with GIT. As for the "TransportCalculator" class, I am currently investigating the possibility of transposing between musical keys instead of semitones. |
No problem! |
The code I propose is approximately 99.97% faster than the original code.
The functions have been embedded in a separate HTML page and tested with Chromium Browser,
comparing a loop of 2,000,000 consecutive instructions, and the return values have been compared
with each other without errors, matching the previous code.
// for (halftone = -1000000; halftone <1000000; halftone++) {...}
WrapAroundCheck_Old() 72426 milliseconds for 2000000 operations
WrapAroundCheck_New() 15 milliseconds for 2000000 operations
Performance improvements: 99.97928920553393%