perf(history): skip props lookup work for non-matching source_adapter#281
Draft
bluetoothbot wants to merge 1 commit into
Draft
perf(history): skip props lookup work for non-matching source_adapter#281bluetoothbot wants to merge 1 commit into
bluetoothbot wants to merge 1 commit into
Conversation
When source_adapter is set, move the adapter filter to right after the Device1 props existence check, before reading address/rssi and running the rssi dedup. Avoids per-non-matching dict lookups on the hot path and defends against KeyError on Address/Alias for malformed entries under unrelated adapters. No behavior change for callers — when source_adapter is None the filter is a no-op, and when set, entries from other adapters never affect the rssi dedup since they were never inserted anyway. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #281 +/- ##
==========================================
- Coverage 99.61% 99.61% -0.01%
==========================================
Files 14 14
Lines 522 521 -1
Branches 48 48
==========================================
- Hits 520 519 -1
Partials 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Move the
source_adapterfilter inload_history_from_managed_objectsto right after theorg.bluez.Device1props existence check, before reading address/rssi and running the rssi dedup.Why
When a caller passes
source_adapter="hci0", every managed-object entry under/org/bluez/hci1/...(or any non-matching adapter) currently runs through:props["Address"]lookupprops.get("RSSI", MIN_RSSI)lookuphistory.get(address)lookup + rssi comparison…only to be discarded at the
source_adaptercheck. With one BlueZ instance commonly exposing several adapters and dozens-to-hundreds of devices each, this is per-discarded-device work on a hot path that is otherwise cheap.Bonus: defends against
KeyErroronAddress/Aliasfor malformed entries under unrelated adapters — those can't crash a single-adapter call anymore.How
The split + filter moves up four lines. No new allocations:
path_str.split("/")already happens once per accepted device, now happens once perDevice1entry instead. Non-Device1paths still short-circuit before the split.Behavior
Unchanged. When
source_adapter is None, the filter is a no-op. When set, entries from other adapters were never inserted intohistoryanyway, so they couldn't affect the rssi dedup — moving the filter just decides "skip" earlier.Testing
poetry run pytest tests/— 51 passed (includingtest_history_with_rssi_checkwhich exercises both thesource_adapter=Noneandsource_adapter="hci1"paths).ruff checkclean.Quality Report
Changes: 1 file changed, 4 insertions(+), 6 deletions(-)
Code scan: clean
Tests: passed (1
PASSED)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline