Skip to content

Re-sort aiohttp resources at startup by least cost#95717

Closed
bdraco wants to merge 1 commit into
devfrom
aiohttp_linear_search
Closed

Re-sort aiohttp resources at startup by least cost#95717
bdraco wants to merge 1 commit into
devfrom
aiohttp_linear_search

Conversation

@bdraco
Copy link
Copy Markdown
Member

@bdraco bdraco commented Jul 2, 2023

This is an experiment. I've been running this for a few months while looking for a better solution which has not appeared so I'm opening a PR in case someone has an idea... EDIT: opening the PR provided some inspiration and #95721 is an alternate solution

A "better" solution will likely have more complexity so as this does solve the problem in the short term (it will be more of a problem in the future as we add more resources to aiohttp) with low complexity this might be the best path forward.

aiohttp seems to have given up on the tree approach they started because of how large of a breaking change it would be so I have little confidence this will ever get solved upstream.

Proposed change

Each resource added to aiohttp slows it down a bit because it has to do a linear search to resolve resources every time a request is made. DynamicResource need to run a regex to reject or accept. By moving them further in the list we can get the frontend to load faster since we don't have to hit a lot of regexes to find the route that will accept.

aiohttp does a linear search for resources under the hood. We can move the cheap ones to the front since we have to make it through them all to find the ones we want.

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:

aiohttp does a linear search for resources under the hood.
We can move the cheap ones to the front since we have to
make it through them all to find the ones we want
@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented Jul 2, 2023

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

Code owner commands

Code owners of http can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign http Removes the current integration label and assignees on the pull request, add the integration domain after the command.

bdraco added a commit that referenced this pull request Jul 2, 2023
@bdraco bdraco mentioned this pull request Jul 2, 2023
20 tasks
@bdraco
Copy link
Copy Markdown
Member Author

bdraco commented Jul 2, 2023

I think #95721 is a better solution

@bdraco bdraco closed this Jul 2, 2023
balloob pushed a commit that referenced this pull request Jul 3, 2023
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 3, 2023
@bdraco bdraco deleted the aiohttp_linear_search branch November 1, 2023 04:51
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.

1 participant