GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@sashko1988 sashko1988 commented May 28, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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:

  1. 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?
  2. Should I create a changelog entry?
  3. Should I add myself to the authors?)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sashko1988
update logic of _check_initialpaths_for_relpath
660b5fa
RonnyPfannschmidt
RonnyPfannschmidt approved these changes May 28, 2025
View reviewed changes

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Copy link
Copy Markdown
Member

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
All reactions
  • 🎉 1 reaction
@sashko1988
add changelog entry
dc8a937
update AUTHORS
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label May 28, 2025
@pre-commit-ci
[pre-commit.ci] auto fixes from pre-commit.com hooks
485a225
for more information, see https://pre-commit.ci
@sashko1988 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
RonnyPfannschmidt
RonnyPfannschmidt previously requested changes May 28, 2025
View reviewed changes
Comment thread changelog/13420.improvement.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

sashko1988 and others added 3 commits May 28, 2025 14:08
@sashko1988
update changelog entry
ee36ee4
@pre-commit-ci
[pre-commit.ci] auto fixes from pre-commit.com hooks
130c16a
for more information, see https://pre-commit.ci
@sashko1988
fix failing docs build - remove reference to internal class
8f807a6
@sashko1988
sashko1988 requested a review from RonnyPfannschmidt May 28, 2025 13:35
nicoddemus
nicoddemus approved these changes May 28, 2025
View reviewed changes

@nicoddemus nicoddemus left a comment

Copy link
Copy Markdown
Member

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.

Nice catch! Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sashko1988 reacted with hooray emoji
All reactions
  • 🎉 1 reaction
Comment thread changelog/13420.improvement.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@nicoddemus
Update changelog/13420.improvement.rst
58a5cc0
@nicoddemus
nicoddemus dismissed RonnyPfannschmidt’s stale review May 28, 2025 21:22

Changelog updated as requested.

@nicoddemus

nicoddemus commented May 28, 2025

Copy link
Copy Markdown
Member

Should I add myself to the authors?)

Yes, you are welcome to. 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

RonnyPfannschmidt
RonnyPfannschmidt approved these changes May 28, 2025
View reviewed changes
@sashko1988

sashko1988 commented May 29, 2025

Copy link
Copy Markdown
Contributor Author

@nicoddemus thanks for editing the changelog entry!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sashko1988

sashko1988 commented May 29, 2025

Copy link
Copy Markdown
Contributor Author

@nicoddemus @RonnyPfannschmidt
Can it also be backported to 8.3.x?

RonnyPfannschmidt and nicoddemus reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nicoddemus nicoddemus added the backport 8.3.x label May 29, 2025
@nicoddemus
nicoddemus merged commit bd6877e into pytest-dev:main May 29, 2025
@patchback

patchback Bot commented May 29, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Backport to 8.3.x: 💚 backport PR created

✅ Backport PR branch: patchback/backports/8.3.x/bd6877e5874b50ee57d0f63b342a67298ee9a1c3/pr-13448

Backported as #13451

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

All reactions

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
@sashko1988 @nicoddemus @patchback
Improve nodes._check_initialpaths_for_relpath performance (#13448)
a8456a8
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)
@patchback patchback Bot mentioned this pull request May 29, 2025
[PR #13448/bd6877e5 backport][8.3.x] Improvement: #13420 - Update logic of nodes._check_initialpaths_for_relpath #13451
Merged
nicoddemus added a commit that referenced this pull request May 29, 2025
@patchback @sashko1988 @nicoddemus
Improve nodes._check_initialpaths_for_relpath performance (#13448) (#…
26c3722
…13451)

Use `Path` facilities to greatly improve performance of `nodes._check_initialpaths_for_relpath` (see #13448 for performance comparison).

Related: #13420, #13413.

---------


(cherry picked from commit bd6877e)

Co-authored-by: Sashko <[email protected]>
Co-authored-by: Bruno Oliveira <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@RonnyPfannschmidt RonnyPfannschmidt RonnyPfannschmidt approved these changes
@nicoddemus nicoddemus nicoddemus approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

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.

3 participants

@sashko1988 @nicoddemus @RonnyPfannschmidt
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.