-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
HID-Parser perfomance improvements #4894
HID-Parser perfomance improvements #4894
Conversation
This is Ready For Review, but depends on #4718. Therefore it's in state Draft. |
389ce1a
to
22cf892
Compare
Fixed some typos in documentation
…efault undefined is handled in the code already. In existing mappings this argument is seldom used)
Qt uses JavaScriptCore as its interpreter and JIT. These seem to be some resources on learning JSC internals: That said, IMO discussing javascript performance characteristics of semantically equivalent language constructs is a lost cause. No matter the language, the first thing to look at when optimizing code are the algorithms, something this code is clearly not very good at (see many crude nested searches present). Replacing the worst case offender with a hashmap was definitely a good step. Anymore probably requires a redesign anyways. |
…ap.prototype.get() returns also undefined, in case that the key doesn't exist in the map
I benchmarked different loop variants using the most calculation demanding CO of my Z2 mapping (changing the values of the 7segment display which means 21 7bit fields changed at each call of this CO). I used my two Windows laptops, and build this PR locally on each of them:
I used three versions of
The results are very good repeatable, but the std. deviation was much higher on the old dual-core laptop. Most propably, because other threads needed CPU time.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good. However I am not able to test it.
In this case I think we can rely on @JoergAtGithub test results with the Tractor Z2.
I have just left request to document the performance implications in the code. @Swiftb0y is it than read for merge?
Have you measured the performance when you abstract the loop into a function? Something like this: function FastForIn(object, body) {
const objKeyArray = Object.keys(object);
let objKeyArrayIdx = objKeyArray.length;
while (objKeyArrayIdx--) {
body(objKeyArray[objKeyArrayIdx]);
}
} |
I tried your "abstract the loop into a function" approach an the performance seems to be the same as my version with the while loop. But I couldn't apply it everywhere, because the following loop contains mixxx/res/controllers/common-hid-packet-parser.js Lines 1700 to 1730 in 18ae5e9
|
Thank you for investigating. In that case, I'd prefer if the abstracted version was used where possible and if not, the "inlined" version is fine. wdyt? |
I prepared a version "abstract the loop into a function" and tested it before pushing it to this PR JoergAtGithub@bded951 . On the Windows11 Octal-Core I got the same execution time as before, but on the Windows7 Dual-Core is was significiantly slower. I repeated the measurements several times:
|
IMO thats still good enough. In the end, it doesn't make sense to micro-optimize loops in JS. We should instead optimize for readability and maintainability. IMO the loop in the function is the best of both worlds. Do you agree? |
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. LGTM
There are still unresolved comments by @daschuer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thank you very much.
This is based on PR #4718
The function HIDController.getOutputField contained some calculation intensive nested for loops. Since HIDController.getOutputField is an often executed function, this had a severe performance impact, especially for HID controllers with long reports.
This PR replaces this nested loops by a lookup map.
In practice the execution time of some CO callbacks for my Traktor Z2 dropped from ~6ms to 1.2ms.
Additionl loop optimization brings it further down to 755ms