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

perf: avoid creating a task for debounced listener update #990

Merged
merged 2 commits into from
Jun 8, 2024

Conversation

bdraco
Copy link
Contributor

@bdraco bdraco commented Jun 8, 2024

Nothing was being awaited in _debounced so it could be a normal function decorated with @callback to run in the event loop and did not need to be a coro. This avoids creating a task when the async_call_later fires

Note as with #989, I don't use mqtt/teslamate so I have no real world test case for this

@bdraco bdraco changed the title Avoid creating a task for the debounced listener update pref: avoid creating a task for the debounced listener update Jun 8, 2024
@bdraco bdraco force-pushed the useless_coro branch 3 times, most recently from 584bce8 to 087490e Compare June 8, 2024 05:43
self._debounce_task = async_call_later(
self.hass, delay_since_last, partial(self._debounced, max_delay)
# Schedule the call to _async_debounced, pass max_delay using partial
self._cancel_debounce_timer = async_call_later(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async_call_later does not return a task, it returns a callback that can be used to cancel the timer

@bdraco bdraco changed the title pref: avoid creating a task for the debounced listener update perf: avoid creating a task for the debounced listener update Jun 8, 2024
Nothing was being awaited in _debounced so it could be
a normal function decorated with @callback to run in
the event loop and did not need to be a coro. This
avoids creating a task when the async_call_later fires
@alandtse alandtse changed the title perf: avoid creating a task for the debounced listener update perf: avoid creating a task for debounced listener update Jun 8, 2024
@alandtse alandtse merged commit 4746944 into alandtse:dev Jun 8, 2024
4 of 5 checks passed
@bdraco bdraco deleted the useless_coro branch June 8, 2024 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants