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

Cache the response from config/entity_registry/list #74443

Merged
merged 5 commits into from
Jul 6, 2022

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Jul 5, 2022

This is part of an optimization cycle to improve the responsiveness of the UI during first pickup and startup

Proposed change

Reverts #74378 and replaces this with a cache instead.

When doing additional testing, the list comp was still
slow on my RPI 32bit test platform, and we still had
the json encode overhead (while its much better with
orjson, its still not trivial).

This reduces the CPU spike
when everything reconnects at startup. The device
registry does show up on the profile still, and while its
small for one device reconnecting, it could have an impact
if they have 5-6 and the system is cpu bound during startup
so we might want to do that one as well in the future
but addressing the static files path is probably time
better spent.

Flame graph of an initial websocket connect
on cache hit its below the sampling threshold.

And yes it does look like static files call pathlib which is doing
I/O in the event loop but that seems to be copied from
aiohttp so I'm not sure if it should or not

Screen_Shot_2022-07-04_at_11_32_33_PM

Similar strategy as

def cached_event_message(iden: int, event: Event) -> str:
except its cleared when the registry is updated instead of the
event itself

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)
  • 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
  • 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.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (config) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@bdraco
Copy link
Member Author

bdraco commented Jul 5, 2022

We should probably resolve the symlink and stat the files in the executor. It might make the request a bit slower though. The upside is that if you open the UI during startup when the system is IO bound it won't block the event loop waiting to be able to run the readlink/stat syscslls

@bdraco
Copy link
Member Author

bdraco commented Jul 5, 2022

Actually for the frontend files if we aren't in dev mode it might make more sense to cache the filepath lookup

@bdraco bdraco marked this pull request as ready for review July 5, 2022 13:27
@bdraco bdraco requested a review from a team as a code owner July 5, 2022 13:27
bdraco added a commit to bdraco/home-assistant that referenced this pull request Jul 6, 2022
@bdraco
Copy link
Member Author

bdraco commented Jul 6, 2022

This one should be good to go. #74474 takes care of the existing I/O in the event loop

@balloob balloob merged commit ce35324 into home-assistant:dev Jul 6, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants