Skip to content

perf: caching#10954

Open
radoering wants to merge 1 commit into
python-poetry:mainfrom
radoering:perf/caching
Open

perf: caching#10954
radoering wants to merge 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.

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