Skip to content
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

Linear searching is a performance bottleneck in BlueZManager.get_services with many devices #927

Closed
bdraco opened this issue Aug 8, 2022 · 3 comments · Fixed by #966 or #969
Closed
Labels
Backend: BlueZ Issues and PRs relating to the BlueZ backend

Comments

@bdraco
Copy link
Contributor

bdraco commented Aug 8, 2022

Properties are indexed well for _wait_condition but building the services can be expensive when the number of properties stored gets to a large number. Its noticeable when there ~20 bluetooth devices that have their services resolved in the properties dict

@bdraco
Copy link
Contributor Author

bdraco commented Aug 8, 2022

I'm planning on working on a solution for this

@bdraco
Copy link
Contributor Author

bdraco commented Aug 9, 2022

Jc2k/aiohomekit#135

It looks like sometimes they are missing as well

@bdraco
Copy link
Contributor Author

bdraco commented Aug 9, 2022

Might also be the cause of home-assistant/core#75962 (comment)

Switchbot communication failed. Stopping trying
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 81, in _sendcommand
return await self._send_command_locked(key, command)
File "/usr/local/lib/python3.10/site-packages/switchbot/devices/device.py", line 122, in _send_command_locked
await client.start_notify(read_char, _notification_handler)
File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 809, in start_notify
raise BleakError(
bleak.exc.BleakError: Characteristic with UUID None could not be found!

@dlech dlech added the Backend: BlueZ Issues and PRs relating to the BlueZ backend label Aug 20, 2022
dlech added a commit that referenced this issue Aug 26, 2022
This adds maps to improve performance when calling get_services().

Previously we had to enumerate all BlueZ D-Bus objects for each service,
characteristic and descriptor. When there were many devices, this was
a performance bottleneck.

Instead, we can create a map of the D-Bus object tree as new interfaces
appear, then use this map as an efficient way to find the child D-Bus
object paths in the GATT tree.

Fixes #927.
@dlech dlech mentioned this issue Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend: BlueZ Issues and PRs relating to the BlueZ backend
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants