bthidhub icon indicating copy to clipboard operation
bthidhub copied to clipboard

Use mypyc to compile modules

Open Dreamsorcerer opened this issue 3 years ago • 6 comments

This compiles the modules which are involved in processing BT/HID events in order to increase performance.

Fixes #24

Dreamsorcerer avatar May 18 '21 19:05 Dreamsorcerer

Hi Sam,

I won't be able to look at the pull request for the next few weeks, but I appreciate your contributions. I have invited you as a contributor to this repository, so feel free to merge your changes to the main branch

ruundii avatar May 19 '21 12:05 ruundii

@ruundii Unfortunately, I've just realised it doesn't really resolve the lag issue after all (though may still be a good idea overall).

When I start the application, there is no noticeable lag. If I disconnect my laptop and reconnect it (from the laptop's BT settings), then often the lag appears after reconnecting. Restarting the app will often go back to being lag-free. Additionally, whenever I have the BT settings open on my laptop (Ubuntu) there is a very high level of lag. As if the laptop's scanning slows down the RPi's processing time or something (but, this doesn't happen when the mouse is connected directly).

Any ideas what might be causing this lag after reconnection?

I've tried profiling the app, but I don't see any major differences. Maybe there is more time spent in asyncio_glib/glib_selector.py, but I'm not too convinced the problem is there, it might be an issue not exposed by the profiler.

Dreamsorcerer avatar May 19 '21 17:05 Dreamsorcerer

from when i was developing and profiling it I remember few things which may cause issues

  1. scanning. as far as I remember when you open BT in ubuntu it does scanning, basically, BT slows down then. It is just a thing in BT protocol, basically, it needs to send/receive many messages over limited number of frequencies etc. so it is bound to slow down. At some point I want to check if it would be better to utilise HoG/GATT for the bthidhub, possibly this will solve some of such issues, but it is a big thing to try out. (e.g. see https://github.com/HeadHodge/Bluez-HID-over-GATT-Keyboard-Emulator-Example/blob/main/gattServer.py)

  2. there is master/slave role in Bluetooth. basically out of two connected devices one is 'controlling the clock'. it is very important for RPi to be in master role for the BT connection with the host PC, otherwise it is bound to lag. bluetooth_devices.py sets this master role. I would check the state of master role when lag is occurring to ensure it is set

  3. Wifi. Unfortunately I found sometimes massive interference between Bluetooth and Wifi.

ruundii avatar May 19 '21 17:05 ruundii

I think you've got it. It appears that it sets to master on startup, but doesn't do it again when the device reconnects. I'll have a look tomorrow and create a PR to fix it.

Dreamsorcerer avatar May 19 '21 18:05 Dreamsorcerer

Nevermind, that only took 5 mins. :P

Dreamsorcerer avatar May 19 '21 18:05 Dreamsorcerer

I'm happy to merge the other PRs, but I think this one is probably best if tested by someone other than me first.

Also, when you do have some time, it'd be a great help if you could take a look at #21. This is the last issue causing me major problems, and the problem appears to be in the forked bluez, which is not something I know how to debug.

Dreamsorcerer avatar May 21 '21 20:05 Dreamsorcerer