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

DNM: attempt to speed up caching the split of the netloc #1427

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,7 @@ def __setstate__(self, state):

def _cache_netloc(self) -> None:
"""Cache the netloc parts of the URL."""
c = self._cache
split_loc = split_netloc(self._netloc)
c["raw_user"], c["raw_password"], c["raw_host"], c["explicit_port"] = split_loc
self._cache.update(_split_netloc_to_cache(self._netloc))

def is_absolute(self) -> bool:
"""A check for absolute URLs.
Expand Down Expand Up @@ -1403,6 +1401,18 @@ def human_repr(self) -> str:
_DEFAULT_ENCODE_SIZE = 512


@lru_cache
def _split_netloc_to_cache(netloc: str) -> dict[str, Any]:
"""Split netloc into cache."""
user, password, host, port = split_netloc(netloc)
return {
"raw_user": user,
"raw_password": password,
"raw_host": host,
"explicit_port": port,
}


@lru_cache(_DEFAULT_IDNA_SIZE)
def _idna_decode(raw: str) -> str:
try:
Expand Down