-
Notifications
You must be signed in to change notification settings - Fork 307
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
Optimize BlueZ device watchers and condition callbacks to avoid linear searches #1400
Conversation
rebasing.. |
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.
Thanks for PR. Did you measure the performance difference?
bleak/backends/bluezdbus/manager.py
Outdated
): | ||
def _wait_condition_callback(changed: Dict[str, Any]) -> None: | ||
"""Callback for when a property changes.""" | ||
if changed.get(property_name) == property_value: |
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 think there could be some potential issues here with None == False
. As mentioned in another comment, might be simpler to just leave it the way it was without passing the changed
arg.
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 changed the incoming to pull from self_interface.get
so None
will still work
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 left it passing the value because I always worry about race conditions when we have to look it up again. Not a problem right now but could be in the future if something gets refactored
Co-authored-by: David Lechner <[email protected]>
This reverts commit e009230.
It was ~18% faster with my locks when I have a lot of devices but its going to vary widely depending on how many devices since its a Time complexity issue |
marking as draft while I clean up and retest |
self._run_advertisement_callbacks( | ||
message.path, cast(Device1, self_interface), changed.keys() | ||
device_path, cast(Device1, self_interface), changed.keys() | ||
) |
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.
This could be indexed by adapter when the user has multiple bluetooth adapters it has to reject callbacks for the wrong adapter. But that should be another PR in the future (maybe not needed though since not many people will have multiple adapters)
Co-authored-by: David Lechner <[email protected]>
Co-authored-by: David Lechner <[email protected]>
retesting on production one more time just to be sure |
all good 👍 |
Thanks for the review. Will be very happy to get a new release so we can get esphome/aioesphomeapi#528 sorted out |
Hopefully we can get a release by the end of the week. There is still a Windows issue I would like to address and also prepare for Python 3.12. |
needs #1399