Replies: 1 comment
-
This is interesting, thank you. So it looks like kanata is very CPU efficient right now. But, what about latency? Do you think there's a room for improvement in this regard? Also same question about jitter; besides channels is there anything that could cause jitter?
This doesn't sound like a good idea to me. It will just increase latency, no matter the refresh rate. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Out of curiosity for potential efficiency gains in the keyboard processing, I ran
cargo flamegraph
again to see where Kanata spends its CPU time. It's only on Linux for now, but I would guess Windows looks pretty similar.The bulk of the CPU time is spent in syscalls:
sleep
to wait between ticks in the processing loop (86.5%)clock__gettime
to get accurate time measurements for computing ticks (3.7%)write
for sending keyboard events out of uinput (2.5%)epoll_wait
for blocking on user keyboard inputs (1.8%)futex_wait
for blocking on channel communication (1%)With init code being about 1.5% of the runtime and perf being another 1.1%, there is not much point in trying to optimize the algorithms/processing, e.g. in the processing loop or in the keyberon code. The code that is not syscalls makes up very little of the CPU time. Any room for improvement would be in reducing syscalls.
After the fix in #114, the major pain on Linux is gone. Perhaps, since the max refresh rate of any monitor that I know of is 240 Hz, Kanata could sleep for more than 1ms - maybe or 4ms, and then it would always do multiple ticks per sleep.
Another point is the use of channels. In CPU time it's not a big deal, but maybe they have latency impact when the system is at high load. At high load, waking up the multiple threads (event loop, processing loop, pre-processing loop with LLHOOK) to finish sending a key event could result in a visible impact. On one of my 4 core (😢) Windows machines though, I haven't noticed it being an issue.
Click the link (not the image)
![flamegraph](https://private-user-images.githubusercontent.com/6634136/262577550-6dfb2736-19e1-4aba-9ea5-807c9f661f58.svg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAyNzIwNDMsIm5iZiI6MTcyMDI3MTc0MywicGF0aCI6Ii82NjM0MTM2LzI2MjU3NzU1MC02ZGZiMjczNi0xOWUxLTRhYmEtOWVhNS04MDdjOWY2NjFmNTguc3ZnP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDZUMTMxNTQzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OWJkODc0M2IyZWEzMTY1YzYzMTQ4YzE3Njg5MmQ3MGI4YmI3NTg3NTI5OTViOWU2MDI2OTRiM2E0NGUxZTM3NiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.2CPy5tfQT6UqSHKGZjuXz4MtJQLJvvuxBGwLFud4dRA)
https://github.com/jtroo/kanata/assets/6634136/6dfb2736-19e1-4aba-9ea5-807c9f661f58
Beta Was this translation helpful? Give feedback.
All reactions