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

Problems with wheel_file_re #9769

Closed
AlekseyLobanov opened this issue Oct 14, 2024 · 1 comment · Fixed by #9770
Closed

Problems with wheel_file_re #9769

AlekseyLobanov opened this issue Oct 14, 2024 · 1 comment · Fixed by #9770
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@AlekseyLobanov
Copy link
Contributor

Description

Hello.

I found that performance of the current wheel_file_old may be really bad O(N^4) on some inputs. It may be not a serious problem but for end user it will be almost impossible to find and troubleshoot.

After performance fix I also found .dist-info extension is working as expected.

We can verify performance with this POC

import re
import time
from contextlib import contextmanager
import sys

wheel_file_old = re.compile(
    r"^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))"
    r"(-(?P<build>\d.*?))?"
    r"-(?P<pyver>.+?)"
    r"-(?P<abi>.+?)"
    r"-(?P<plat>.+?)"
    r"\.whl|\.dist-info$",
    re.VERBOSE,
)
wheel_file_re_new= re.compile(
    r"^(?P<namever>(?P<name>[^-]+)-(?P<ver>[^-]*))"
    r"(-(?P<build>\d[^-]*))?"
    r"-(?P<pyver>[^-]+)"
    r"-(?P<abi>[^-]+)"
    r"-(?P<plat>[^-]+)"
    r"(?:\.whl|\.dist-info)$",
    re.VERBOSE,
)


@contextmanager
def duration(text):
    begin_at = time.monotonic()
    yield
    delta = time.monotonic() - begin_at
    print(f"{text:20} takes {delta:0.6f}s")


pattern = '0-0' + '-' * int(sys.argv[1])

with duration("Current (old) re"):
    wheel_file_old.match(pattern)
with duration("New re"):
    wheel_file_re_new.match(pattern)

Example output

➜ python poetry-poc.py 250
Current (old) re     takes 0.942238s
New re               takes 0.000003s

Workarounds

  • Performance issues should not be a problem for almost all valid wheel names
  • Do not use wheels with .dist-info extension

Poetry Installation Method

pip

Operating System

Ubtuntu

Poetry Version

2.0.0.dev0

Poetry Configuration

cache-dir = "/home/alex/.cache/pypoetry"
experimental.system-git-client = false
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
keyring.enabled = true
requests.max-retries = 0
solver.lazy-wheel = true
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"  # /home/alex/.cache/pypoetry/virtualenvs
virtualenvs.prefer-active-python = false
virtualenvs.prompt = "{project_name}-py{python_version}"

Python Sysconfig

any

Example pyproject.toml

any

Poetry Runtime Logs

any
@AlekseyLobanov AlekseyLobanov added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Oct 14, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant