Skip to content

Commit

Permalink
Use aiohttp-fast-url-dispatcher to avoid linear searching to route urls
Browse files Browse the repository at this point in the history
The default `UrlDispatcher` implementation does a linear search every which can have a significant [TimeComplexity](https://wiki.python.org/moin/TimeComplexity) when dispatching urls when there are a lot of routes. `FastUrlDispatcher` keeps an index of the urls which allows for fast dispatch.

This solution was original implemented in core as
https://github.com/home-assistant/core/blob/241e8560e99da4cbd3c9f763d77cfbd8badb1c66/homeassistant/components/http/__init__.py#L592

It is now in a PyPI package so it can be reused in other projects
  • Loading branch information
bdraco committed Nov 8, 2023
1 parent d634273 commit 869161d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
aiodns==3.1.1
aiohttp==3.8.6
aiohttp-fast-url-dispatcher==0.1.0
async_timeout==4.0.3
atomicwrites-homeassistant==1.4.1
attrs==23.1.0
Expand Down
2 changes: 2 additions & 0 deletions supervisor/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any

from aiohttp import web
from aiohttp_fast_url_dispatcher import FastUrlDispatcher, attach_fast_url_dispatcher

from ..const import AddonState
from ..coresys import CoreSys, CoreSysAttributes
Expand Down Expand Up @@ -64,6 +65,7 @@ def __init__(self, coresys: CoreSys):
"max_field_size": MAX_LINE_SIZE,
},
)
attach_fast_url_dispatcher(self.webapp, FastUrlDispatcher())

# service stuff
self._runner: web.AppRunner = web.AppRunner(self.webapp)
Expand Down

0 comments on commit 869161d

Please sign in to comment.