-
Notifications
You must be signed in to change notification settings - Fork 303
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
Index BlueZ advertisement_callbacks by adapter #1632
Conversation
cbe6f09
to
3902d34
Compare
3902d34
to
fbf9d1c
Compare
continue | ||
|
||
adapter_path = device["Adapter"] | ||
for callback in self._advertisement_callbacks[adapter_path]: |
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.
Average time complexity should now be: O(callbacks)
instead of O(adapters * callbacks)
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.
Do you have before and after flamegraphs or something like that showing the difference?
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.
fbf9d1c
to
9d95087
Compare
continue | ||
|
||
adapter_path = device["Adapter"] | ||
for callback in self._advertisement_callbacks[adapter_path]: |
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.
Do you have before and after flamegraphs or something like that showing the difference?
Running with 6 Bluetooth adapters its ~28% less time spent in It can be roughly benchmarked with import timeit
from collections import defaultdict
def callback():
pass
advertisement_callbacks: defaultdict[str, list] = defaultdict(list)
test_adapter = "/org/bluez/hci9"
for i in range(10):
advertisement_callbacks[f"/org/bluez/hci{i}"] = [callback]
advertisement_callbacks_orig = [
(callback, adapter_path)
for callback, adapter_path in advertisement_callbacks.items()
]
def new():
for callback in advertisement_callbacks[test_adapter]:
pass
def orig():
for callback, adapter_path in advertisement_callbacks_orig:
if adapter_path != test_adapter:
continue
print(timeit.timeit(orig, number=1000000))
print(timeit.timeit(new, number=1000000)) orig
new
|
- Instead of doing a linear search of all the callbacks to find the one for the adapter, store them in a dict so the adapter path can be looked up - Remove unused arg from _run_advertisement_callbacks Co-authored-by: David Lechner <[email protected]>
99a1e1e
to
3e6c75e
Compare
Thanks! |
Thanks |
Instead of doing a linear search of all the callbacks to find the one for the adapter, store them in a dict so the adapter path can be looked up
Remove unused arg from _run_advertisement_callbacks
If the pull request adds functionality, the docs should be updated.
Modify the
CHANGELOG.rst
, describing your changes as is specified by theguidelines in that document.
The pull request should work for Python 3.8+ on the following platforms:
Squash all your commits on your PR branch, if the commits are not solving
different problems and you are committing them in the same PR. In that case,
consider making several PRs instead.
Feel free to add your name as a contributor to the
AUTHORS.rst
file!