Skip to content

perf: cache link objects that have been created lazily#10953

Open
radoering wants to merge 1 commit into
python-poetry:mainfrom
radoering:perf/link-cache-4
Open

perf: cache link objects that have been created lazily#10953
radoering wants to merge 1 commit into
python-poetry:mainfrom
radoering:perf/link-cache-4

Conversation

@radoering

Copy link
Copy Markdown
Member

#10951 prevented the creation of unnecessary link objects. However, this also resulted in link objects that were requested multiple times being created multiple times. Depending on a project's dependencies the first or the latter is more relevant. Thus, a two-stage cache makes sense to get the best of both.

@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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/poetry/repositories/link_sources/base.py" line_range="175-180" />
<code_context>
         return True

     @cached_property
-    def _link_cache(self) -> LinkCache:
-        raise NotImplementedError()
+    def _link_factory_cache(self) -> LinkFactoryCache:
+        """ATTENTION:
+        The factories should only be called in links_for_version
+        so that the __link_cache, which avoids to call the same factory twice,
+        is populated.
+        """
</code_context>
<issue_to_address>
**nitpick (typo):** Polish the wording in the `_link_factory_cache` docstring for clarity.

The phrase "avoids to call the same factory twice" is awkward. Please rephrase to something like "avoids calling the same factory twice" for smoother wording.

```suggestion
    def _link_factory_cache(self) -> LinkFactoryCache:
        """ATTENTION:
        The factories should only be called in links_for_version
        so that the __link_cache, which avoids calling the same factory twice,
        is populated.
        """
```
</issue_to_address>

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.

Comment thread src/poetry/repositories/link_sources/base.py
python-poetry#10951 prevented the creation of unnecessary link objects. However, this also resulted in link objects that were requested multiple times being created multiple times. Depending on a project's dependencies the first or the latter is more relevant. Thus, a two-stage cache makes sense to get the best of both.
@radoering radoering force-pushed the perf/link-cache-4 branch from 5fb0de0 to a341710 Compare June 13, 2026 11:16
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