-
Notifications
You must be signed in to change notification settings - Fork 71
Firngrod/improved same half logic #1420
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
base: master
Are you sure you want to change the base?
Firngrod/improved same half logic #1420
Conversation
| void PostponerQuery_InfoByQueueIdx(uint8_t idx, postponer_buffer_record_type_t** press, postponer_buffer_record_type_t** release); | ||
| void PostponerQuery_FindFirstReleased(postponer_buffer_record_type_t** press, postponer_buffer_record_type_t** release); | ||
| bool PostponerQuery_ContainsKeyId(uint8_t keyid); | ||
| typedef bool (*key_state_predicate_t)(key_state_t *keyState); |
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.
I was unsure of whether to go with a predicate or whether to bake the logic into the search function. I like the predicate structure better as it leaves the Secondary Role business logic in secondary_role_driver.c file and the search logic in postponer.c. I do not think there is any real performance cost to doing it this way. Possibly there's a readability cost?
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.
Well, right, what is actually relevant is that the call tree of those utils calls has become quite large, which imposes penalties on both performance and readability due to call overheads.
Also, looking at the code, my implementation of Utils_KeyStateToKeyId is hugely overengineered. That could be simplified down to a oneliner plus or minus edge-case handling - the 64 base is more or less set in stone now.
I prefer baking it into the search, unless you insist on the predicate.
Reasons:
readability cost
seems like a premature generalization / yagni
performance cost is tricky to judge because it depends on what you compare it to, but compared to an unpacked in-place computation, it is huge-ish
I guess the PostponerQuery_FindFirstReleased should issue a single call to Utils_AreKeysOnTheSameHalf with key_state_t* pointers as arguments.
If it makes sense to you, feel free to move Utils_AreKeysOnTheSameHalf logic into postponer (probably as a static function) and unpack its content there.
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.
I will do that. I'm inexperienced in microprocessor development, so I don't have a firm grasp of how much to optimize, and I tend to err or the side of generalization.
| * - MinimumHoldTime - The minimum time that a key must be held for in order to allow it to trigger as secondary. | ||
| * - AcceptTriggersFromSameHalf - Whether or not action keys can be from the same half as the resolution key. |
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.
How up-to-date are these comments being kept? I feel that they are quite eclipsed by the macro reference manual of which any developer is surely aware.
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.
Just as any documentation or comments are in coding projects. When writing it, I felt the need to have a brief reference here, containing whatever I consider relevant for me as a programmer, not having to think about its exhaustiveness or other aspects of a documentation.
I am not dead set on keeping it. If you have a strong desire to just delete it, then feel free to.
They sound fine! :-) |
|
Do any edge cases need to be considered? I have thought about the following, and figured it is actually the desired behavior:
|
kareltucek
left a comment
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.
If you are up to it, then please do refactor the predicate part.
Otherwise, let me know and we can merge it as is.
| * - MinimumHoldTime - The minimum time that a key must be held for in order to allow it to trigger as secondary. | ||
| * - AcceptTriggersFromSameHalf - Whether or not action keys can be from the same half as the resolution key. |
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.
Just as any documentation or comments are in coding projects. When writing it, I felt the need to have a brief reference here, containing whatever I consider relevant for me as a programmer, not having to think about its exhaustiveness or other aspects of a documentation.
I am not dead set on keeping it. If you have a strong desire to just delete it, then feel free to.
| void PostponerQuery_InfoByQueueIdx(uint8_t idx, postponer_buffer_record_type_t** press, postponer_buffer_record_type_t** release); | ||
| void PostponerQuery_FindFirstReleased(postponer_buffer_record_type_t** press, postponer_buffer_record_type_t** release); | ||
| bool PostponerQuery_ContainsKeyId(uint8_t keyid); | ||
| typedef bool (*key_state_predicate_t)(key_state_t *keyState); |
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.
Well, right, what is actually relevant is that the call tree of those utils calls has become quite large, which imposes penalties on both performance and readability due to call overheads.
Also, looking at the code, my implementation of Utils_KeyStateToKeyId is hugely overengineered. That could be simplified down to a oneliner plus or minus edge-case handling - the 64 base is more or less set in stone now.
I prefer baking it into the search, unless you insist on the predicate.
Reasons:
readability cost
seems like a premature generalization / yagni
performance cost is tricky to judge because it depends on what you compare it to, but compared to an unpacked in-place computation, it is huge-ish
I guess the PostponerQuery_FindFirstReleased should issue a single call to Utils_AreKeysOnTheSameHalf with key_state_t* pointers as arguments.
If it makes sense to you, feel free to move Utils_AreKeysOnTheSameHalf logic into postponer (probably as a static function) and unpack its content there.
Yes, you are correct, the first key would go secondary and the two next keys would go primary with mod applied, even though the first one was from the same half. |
|
I think it actually is the correct and desired behavior the way it is :). Just took a few minutes to realize that there is nothing strange about it and that it definitely isn't expected to be a multimod scenario. |
|
I see it like if someone asked if you had considered that they new wooden wrist rest smelled differently from the rubber one. Well, yes it does, it's not really a feature that was aimed for, but it is to be expected, and no one was expected to start actively sniffing it. |
|
Once the other branch merges, I will rebase this one and start working on the changes. |
This improves upon the same half secondary logic in that it no longer actively triggers primary from same half activations, but rather just prevents same half keys from triggering secondary role.
While there are a number of edge case changes from this, none are what I would call bugs, and I think the benefits outweigh the costs.
Benefits:
Arguably negative changes are mainly to do with the timing aspect. One can type out entire key sequences on the same half while a secondary role key is being held with nothing happening before the key is released, which is sort of counter-intuitive, but only actually ever happens if one is determined on testing it. Otherwise, it does ever so slightly the timing of application of some keys, but it's nothing next to just the fact of using Secondary Roles.