Skip to content

perf: fast path single-token repository search#10906

Open
dhimasardinata wants to merge 1 commit into
python-poetry:mainfrom
dhimasardinata:dhimas/fast-single-token-search
Open

perf: fast path single-token repository search#10906
dhimasardinata wants to merge 1 commit into
python-poetry:mainfrom
dhimasardinata:dhimas/fast-single-token-search

Conversation

@dhimasardinata
Copy link
Copy Markdown
Contributor

Repository.search() and simple root-page search commonly receive a single string token from poetry search, but both paths currently wrap it in a one-item list and run any(...) for every package name.

This keeps list-query behavior unchanged and adds a direct string path for the common case.

A small local benchmark over 10,003 package names:

old 1.351595s
new 0.141769s
speedup=9.5x

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code. N/A, no user-facing behavior change.

Local checks:

PYTHONPATH=src uv run --with pytest --with pytest-xdist --with responses --with pytest-mock python -m pytest tests/repositories/test_repository.py tests/repositories/link_sources/test_base.py tests/repositories/test_repository_pool.py -q
uv run --with ruff python -m ruff check src/poetry/repositories/repository.py src/poetry/repositories/link_sources/base.py tests/repositories/test_repository.py
uv run --with ruff python -m ruff format --check src/poetry/repositories/repository.py src/poetry/repositories/link_sources/base.py tests/repositories/test_repository.py
PYTHONPATH=src uv run --with poetry-core --with packaging --with mypy python -m mypy src/poetry/repositories/repository.py src/poetry/repositories/link_sources/base.py
git diff --check

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant