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

Switch back to using call_later for the slow entity update warning #91067

Merged
merged 2 commits into from
Apr 9, 2023

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Apr 8, 2023

Proposed change

I had originally changed this to create a task and wait in #41184 but that does not make sense anymore at least with newer cpython (in hindsight, I don't think it was a good change than either) as the profile now shows the original method is cheaper when I subtract the execution time of the update function.

While cpython has had quite a few improvements in scheduling performance since 2020 and thats helping here, I'm pretty sure I did the profiling wrong in 2020 and didn't account for the task creation moving the execution of the update coro to another branch which hid it from the original profile. 🤦 I never noticed this difference in previous profiles over the last few years since so much has moved to use DataUpdateCoordinator which kept moving the execution path away from here so it never was large enough to pop up until I created a lot of rest sensors for testing another issue.

before (we only care about the cost of the wait as we assume the execution of the update function to be constant):
Screenshot 2023-04-07 at 9 30 35 PM
async_device_update

after (we only care about the cost of call_later and cancel as we assume the execution of the update function to be constant). In this case since there is no task creation we see the actual execution happening lower in the stack:
Screenshot 2023-04-07 at 9 49 51 PM
async_device_update_after

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

I had originally changed this to create a task and wait
in #41184 but that does not make sense anymore with newer
cpython as the profile now shows the original method is cheaper
(or I did it wrong the first time)
@home-assistant home-assistant bot added cla-signed core small-pr PRs with less than 30 lines. labels Apr 8, 2023
@@ -1274,6 +1274,7 @@ async def test_unavailable_device(
hass.config_entries.async_update_entry(
config_entry_mock, options={CONF_POLL_AVAILABILITY: True}
)
await hass.async_block_till_done()
Copy link
Member Author

@bdraco bdraco Apr 8, 2023

Choose a reason for hiding this comment

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

Since there is no longer a task being created in async_update_entity via async_device_update the async_update_entry call wasn't finishing before the entity update started.

@bdraco bdraco marked this pull request as ready for review April 8, 2023 08:16
@bdraco bdraco requested review from StevenLooman and a team as code owners April 8, 2023 08:16
@balloob balloob merged commit 3d1556a into dev Apr 9, 2023
@balloob balloob deleted the revert_switch_to_wait branch April 9, 2023 02:22
@bdraco
Copy link
Member Author

bdraco commented Apr 9, 2023

Thanks

@github-actions github-actions bot locked and limited conversation to collaborators Apr 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed core small-pr PRs with less than 30 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants