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

Avoid creating async_register_repository tasks to register_unknown_repositories #3536

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

bdraco
Copy link
Contributor

@bdraco bdraco commented Mar 1, 2024

Await these in series to avoid creating tasks as they are unlikely to suspend.

fixes #3535

@bdraco
Copy link
Contributor Author

bdraco commented Mar 1, 2024

first call takes 0.00011390098370611668s
second call and after take 3.6492012441158295e-05

await in series seems like a better option here

@bdraco bdraco changed the title Create async_register_repository restore tasks eagerly when available Avoid creating async_register_repository tasks to register_unknown_repositories Mar 1, 2024
@bdraco
Copy link
Contributor Author

bdraco commented Mar 1, 2024

need to do a fresh install to make sure this is ok

@ludeeus
Copy link
Member

ludeeus commented Mar 1, 2024

need to do a fresh install to make sure this is ok

if you do that you should tick the last box in the flow to enable experimental not to give yourself a GitHub rate limit break 😄

@bdraco
Copy link
Contributor Author

bdraco commented Mar 1, 2024

This works well on a fresh install as well

@bdraco bdraco marked this pull request as ready for review March 1, 2024 21:37
Copy link
Member

@ludeeus ludeeus left a comment

Choose a reason for hiding this comment

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

Thanks 👍

I'm currently in the process of changing things around with actions and testing, so If you do not mind I will leave it as-is (open) until that is complete so this can be run against that as well.

It will still go in the next version.

@bdraco
Copy link
Contributor Author

bdraco commented Mar 1, 2024

Its been a problem for years and we have lived with it so no rush at all.

@bdraco
Copy link
Contributor Author

bdraco commented Mar 3, 2024

Screenshot 2024-03-02 at 2 23 22 PM

All the time is spent on line 30

@bdraco
Copy link
Contributor Author

bdraco commented Mar 3, 2024

constructing enums can be oddly slow because they are singletons that have to find the object

don't know if translates to real world savings, but first attempt to make it faster would be:

diff --git a/custom_components/hacs/repositories/integration.py b/custom_components/hacs/repositories/integration.py
index 70b8b547..72fe5f6b 100644
--- a/custom_components/hacs/repositories/integration.py
+++ b/custom_components/hacs/repositories/integration.py
@@ -18,6 +18,7 @@ from .base import HacsRepository
 if TYPE_CHECKING:
     from ..base import HacsBase
 
+CATEGORY_INTEGRATION = HacsCategory.INTEGRATION
 
 class HacsIntegrationRepository(HacsRepository):
     """Integrations in HACS."""
@@ -27,7 +28,7 @@ class HacsIntegrationRepository(HacsRepository):
         super().__init__(hacs=hacs)
         self.data.full_name = full_name
         self.data.full_name_lower = full_name.lower()
-        self.data.category = HacsCategory.INTEGRATION
+        self.data.category = CATEGORY_INTEGRATION
         self.content.path.remote = "custom_components"
         self.content.path.local = self.localpath
 

@ludeeus
Copy link
Member

ludeeus commented Mar 3, 2024

That will eventually be set as a class instead of an instance attribute.
That will be a better saving than doing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A flood of async_register_repository tasks gets created at startup which slows down the event loop
2 participants