Skip to content

Conversation

@henryiii
Copy link
Contributor

@henryiii henryiii commented Nov 27, 2025

Builds on #993.

This makes SpecifierSet creation take 37% less time (on top of the previous 7%) by avoiding extra Version creation. It does it by adding a new signature to _TrimmedRelease with a Version argument instead of only a str, which does a low-cost cast.

There are probably other ways to do this if we don't want to add a Version(version: Version) signature, starting with this as it's simple to open discussion. We could only support this in the subclass for example. Actually, I like not changing API at all when working on performance, so I moved this to the subclass.

@henryiii henryiii changed the title perf: cast Version perf: avoid duplicate Version creation in canonicalize_version Nov 27, 2025
@henryiii henryiii force-pushed the henryiii/perf/cast_version branch from 80ae4a4 to 2afa041 Compare November 27, 2025 04:50
@henryiii henryiii marked this pull request as ready for review November 27, 2025 05:55
@henryiii henryiii marked this pull request as draft November 27, 2025 05:56
@henryiii henryiii marked this pull request as ready for review November 27, 2025 07:23
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
@henryiii henryiii force-pushed the henryiii/perf/cast_version branch from b8b4d5a to 3b4d479 Compare November 27, 2025 16:11
@henryiii
Copy link
Contributor Author

FYI, for an overall improvement measure, reading all requires-python's takes 22.9 seconds with this PR. On 25.0, it takes 58.2 seconds. :)

@henryiii henryiii merged commit 5037c93 into pypa:main Nov 27, 2025
40 checks passed
@henryiii henryiii deleted the henryiii/perf/cast_version branch November 27, 2025 18:18
@henryiii
Copy link
Contributor Author

FYI, the 3.15 flamegraph is starting to look pretty good for SpecifierSet (and therefore Version) creation. The regex is starting to dominate like it should, and most of the other things are pretty even and getting smallish. Mapping split(".") is the second largest part.

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