GeezerVison is showing github.com — Improvement: #13420 - Update logic of nodes._check_initialpaths_for_relpath by sashko1988 · Pull Request #13448 · pytest-dev/pytest
Conversation
sashko1988
commented
May 28, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Updates logic of nodes._check_initialpaths_for_relpath
An even better fix for #13420 and this discussion - #13413
I still wasn't quite happy with the performance.
So after close examination of what nodes._check_initialpaths_for_relpath does, I came up with the PR changes.
Previous logic:
- Iterate over the set of
initial_paths.
- try to find common path of given path and current iteration initial path
- if common path exists - compare it with current iteration initial path
- if common path is the same as the current iteration initial path, find path relative to given path and return
Instead, I propose the following:
- Check if the given path is in
initial_paths.
- if it is, then we know that
relative_to will return ".", and function should return ""
- check failed, check if any parent of the given path is in
initial_paths. If it is, then return the relative path of the given path and that parent.
Performance changes for collecting 1000 tests with stucture described in #13420 and #13413 (times are almost the same for main and 8.3.x branches):
Base
ncalls tottime percall cumtime percall filename:lineno(function)
5821 2.591 0.000 83.172 0.014 nodes.py:547(_check_initialpaths_for_relpath)
With improved logic
ncalls tottime percall cumtime percall filename:lineno(function)
5821 0.020 0.000 0.337 0.000 nodes.py:547(_check_initialpaths_for_relpath)
PS Couple of questions:
- Should I create a separate issue for that PR or associate Slow collection time when tests are not in a relative folder to the current working folder #13420 with it?
- Should I create a changelog entry?
- Should I add myself to the authors?)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever
Let's associate the pr id and mention further improvement
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
sashko1988 reacted with hooray emoji
sashko1988
changed the title
Update logic of nodes._check_initialpaths_for_relpath
Improvement: #13420 - Update logic of nodes._check_initialpaths_for_relpath
May 28, 2025
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
sashko1988 reacted with hooray emoji
Uh oh!
There was an error while loading. Please reload this page.
Should I add myself to the authors?)
Yes, you are welcome to. 👍
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
RonnyPfannschmidt and nicoddemus reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
patchback
Bot
commented
May 29, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
patchback Bot
pushed a commit
that referenced
this pull request
May 29, 2025
Use `Path` facilities to greatly improve performance of `nodes._check_initialpaths_for_relpath` (see #13448 for performance comparison).
Related: #13420, #13413.
---------
Co-authored-by: Bruno Oliveira <[email protected]>
(cherry picked from commit bd6877e)
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|