Skip to content

perf: caching - #10954

Merged
radoering merged 1 commit into
python-poetry:mainfrom
radoering:perf/caching
Jun 19, 2026
Merged

radoering merged 1 commit into
python-poetry:mainfrom
radoering:perf/caching

Conversation

@radoering

Copy link
Copy Markdown
Member

Two caching changes that improve performance for resolving large projects a bit:

  • Apparently, Term.relation and Term.intersection is often not used and constructing the cache in __init__ costs some time. The trick with the cached_property seems simple enough and effective. In case anyone is wondering if we should apply this trick in general: It only makes sense for classes if many instances of the class are created and the cached methods are not used in many instances. We do not create that many instances of other classes where instance methods are cached.
  • _find_packages seems to be called with the same name and constraint multiple times, especially when resolving with overrides.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Wrapping _find_packages_uncached with functools.cache and assigning it to self._find_packages at runtime will bypass any overrides of _find_packages in subclasses; if subclassing is expected here, consider caching at the class/method level or providing an overridable hook instead.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Wrapping `_find_packages_uncached` with `functools.cache` and assigning it to `self._find_packages` at runtime will bypass any overrides of `_find_packages` in subclasses; if subclassing is expected here, consider caching at the class/method level or providing an overridable hook instead.

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.

@radoering
radoering merged commit 026904c into python-poetry:main Jun 19, 2026
51 checks passed
@github-actions

Copy link
Copy Markdown

This pull request 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 Jul 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant