Skip to content

optimize compact_path() in pytest discovery for the common case#26016

Open
vaclavHala wants to merge 1 commit into
microsoft:mainfrom
vaclavHala:compact-discovery-payload-shortcut
Open

optimize compact_path() in pytest discovery for the common case#26016
vaclavHala wants to merge 1 commit into
microsoft:mainfrom
vaclavHala:compact-discovery-payload-shortcut

Conversation

@vaclavHala

Copy link
Copy Markdown

I tested the latest changes to discovery where absolute paths get compacted to global prefix + relative path in each test node, and this change has made the discovery 2 to 3 times slower for us.

The problem is mainly the pathlib.Path.relative_to operation which is relatively expensive:

profile_compact

This PR adds optimization which first checks using simple str.startswith if the test is in some subfolder of the root, in which case creating of the relative path is done as trivial (and cheap) substring:

profile_shortcut

I pass the base paths as both str and pathlib.Path.relative_to so each operation can use whichever form of the base path is needed without having to convert to the other, i.e. str(pathlibPath), which in my testing also adds noticeable overhead.

…ommon case before using expensive relative_to
@vaclavHala

Copy link
Copy Markdown
Author

Hello @eleanorjboyd should I create a separate issue for this?

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