Skip to content

perf: create link objects lazily#10951

Merged
radoering merged 1 commit into
python-poetry:mainfrom
radoering:perf-link-cache-2
Jun 12, 2026
Merged

perf: create link objects lazily#10951
radoering merged 1 commit into
python-poetry:mainfrom
radoering:perf-link-cache-2

Conversation

@radoering

Copy link
Copy Markdown
Member

Another small performance improvement, which makes locking about 10 % faster in some cases.

@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:

  • With LinkCache now holding factories instead of Link instances, repeated iteration over links/links_for_version will rebuild Link objects each time; if these APIs are used frequently in hot paths, consider memoizing the constructed Links per factory or documenting that callers should cache results if they rely on reuse.
  • In HTMLPage._link_cache, the comment notes that links are built eagerly due to lack of a separate filename field; if this becomes a noticeable hotspot, you might consider a lightweight helper that extracts the filename from the URL without constructing a full Link, to align with the lazy strategy introduced for the JSON source.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- With `LinkCache` now holding factories instead of `Link` instances, repeated iteration over `links`/`links_for_version` will rebuild `Link` objects each time; if these APIs are used frequently in hot paths, consider memoizing the constructed `Link`s per factory or documenting that callers should cache results if they rely on reuse.
- In `HTMLPage._link_cache`, the comment notes that links are built eagerly due to lack of a separate filename field; if this becomes a noticeable hotspot, you might consider a lightweight helper that extracts the filename from the URL without constructing a full `Link`, to align with the lazy strategy introduced for the JSON source.

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 d570903 into python-poetry:main Jun 12, 2026
100 of 102 checks passed
radoering added a commit to radoering/poetry that referenced this pull request Jun 13, 2026
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.
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.

2 participants