Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[internal] Use fast_relpath_optional for source root calculation in local_dists. #13091

Merged
merged 1 commit into from
Oct 3, 2021

Conversation

stuhood
Copy link
Sponsor Member

@stuhood stuhood commented Oct 3, 2021

This usage of os.path.relpath was showing up in profiles: it's a notoriously expensive function due to its support for relativizing non-contained paths, and use of os.getcwd (which releases the GIL to execute a syscall, and then needs to re-acquire it).

Switch to fast_relpath_optional.

[ci skip-rust]
[ci skip-build-wheels]

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@stuhood stuhood enabled auto-merge (squash) October 3, 2021 02:22
source.startswith(source_root)
and os.path.relpath(source, source_root) in provided_files
):
source_relpath = fast_relpath_optional(source, source_root)
Copy link
Contributor

@jsirois jsirois Oct 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good if source_roots were non-str / non-PathLike objects so attempts to use os APIs failed, forcing you to convert them to a PathLike 1st. That might be enough pause to see new, perf appropriate API's hung off the source root type.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mm... yea. I think that for a bit there we thought that Path/PurePath were going to be this better API, but it unfortunately seems that that isn't the case.

The challenge is always how widespread these APIs are: there is a huge surface area in the stdlib that takes either str/Path, so any custom path type has a high bar to be worth the extra boilerplate of conversions at the boundary. And we don't have Deref like on the Rust side.

But yea, maybe if it were isolated to a SourceRoot type... although that limits the upside of the custom type as well.

@stuhood stuhood merged commit 6f3e6eb into pantsbuild:main Oct 3, 2021
@stuhood stuhood deleted the stuhood/fast-relpath-for-dists branch October 3, 2021 03:49
@stuhood stuhood mentioned this pull request Oct 11, 2021
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.

3 participants