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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid importing MQTT into core for ServiceInfo dataclass #74418

Merged
merged 13 commits into from Jul 14, 2022

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Jul 4, 2022

Proposed change

Which ever integration triggered the first discovery flow would trigger the python code for mqtt to be loaded. Since most flows would wait until after startup since we queue them until the started event if they come from discovery, this meant that the rpi_power integration which is triggered from the raspberry_pi hardware integration would cause this to happen a lot sooner on RPI platforms. MQTT python code loading would happen at an unexpected time which is a blocking operation since the python files have to be loaded from disk. This caused warnings since everything was waiting for MQTT code load (which takes 8s on my x86_64 spinning disk machine and likely longer on RPi3b+s with an sd card)

Likely fixes #73863

A nice side effect is that if you aren't using MQTT, this saves ~20MiB of RAM on 64bit platforms

I will move the rest of them in a followup PR but I didn't want to do that now since this one should go into beta since they will already be loaded anyways if they are enabled and don't have this issue, but its better to be consistant and have them all in one place in case we add more in the future.

MQTT was getting loaded via config flow since it was needed to type async_step_mqtt
Screen Shot 2022-07-04 at 09 47 10

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 @emontnemery, mind taking a look at this pull request as it has been labeled with an integration (mqtt) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@project-bot project-bot bot added this to Needs review in Dev Jul 4, 2022
@probot-home-assistant
Copy link

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

@bdraco bdraco force-pushed the avoid_importing_mqtt_into_core branch 2 times, most recently from d7e685c to 76f3433 Compare July 4, 2022 15:08
@bdraco bdraco force-pushed the avoid_importing_mqtt_into_core branch from 76f3433 to e248488 Compare July 4, 2022 15:12
@bdraco
Copy link
Member Author

bdraco commented Jul 4, 2022

Its still going to hit __init__.py

@bdraco
Copy link
Member Author

bdraco commented Jul 4, 2022

This still takes 8s on my spinning disk system

>>> from homeassistant.components.mqtt.service_info import MqttServiceInfo

@bdraco
Copy link
Member Author

bdraco commented Jul 4, 2022

I think we need to relo all these dataclasses into their own area

@bdraco bdraco changed the title Avoid importing MQTT into core for discovery dataclass Avoid importing MQTT into core for ServiceInfo dataclass Jul 4, 2022
@bdraco bdraco marked this pull request as ready for review July 4, 2022 16:10
@bdraco bdraco requested review from emontnemery and a team as code owners July 4, 2022 16:10
Dev automation moved this from Needs review to Reviewer approved Jul 5, 2022
@bdraco bdraco mentioned this pull request Jul 5, 2022
22 tasks
@bdraco bdraco removed this from the 2022.7.0 milestone Jul 5, 2022
@bdraco bdraco marked this pull request as draft July 5, 2022 16:17
@bdraco
Copy link
Member Author

bdraco commented Jul 14, 2022

Was on the fence on if this was worth the churn but after #75183 I'm not on the fence anymore and will move this foward and do followups for bluetooth, and the others.

@bdraco bdraco marked this pull request as ready for review July 14, 2022 16:08
@bdraco bdraco merged commit 666f715 into home-assistant:dev Jul 14, 2022
Dev automation moved this from Reviewer approved to Done Jul 14, 2022
bdraco added a commit to bdraco/home-assistant that referenced this pull request Jul 14, 2022
bdraco added a commit to bdraco/home-assistant that referenced this pull request Jul 14, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jul 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

Multiple "is taking over 10 seconds" warnings after updating to 2022.6.7
7 participants