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

fs.Snapshot is declared in Rust #11328

Merged
merged 2 commits into from
Dec 17, 2020

Conversation

stuhood
Copy link
Member

@stuhood stuhood commented Dec 17, 2020

Problem

Our fundamental filesystem types are declared in Python, but declaring them in Rust would cut down on FFI costs, and allow for better error messages by removing some usage of the externs::getattr* functions.

Additionally, the previous change to move fs.Digest to Rust in #10905 missed the optimization opportunity of directly extracting the inner Rust Digest instance.

Solution

In two commits: port fs.Snapshot to Rust, and optimize the conversion of a PyDigest to a Digest.

Result

6% faster runs of ./pants dependencies --transitive ::.

[ci skip-build-wheels]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
…antsbuild#10905.

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Wow, great results. Makes me wonder what other low hanging fruit we have.

How did you identify this as a candidate for optimization?

@@ -13,6 +13,15 @@ class PyDigest:
@property
def serialized_bytes_length(self) -> int: ...

class PySnapshot:
def __init__(self) -> None: ...
Copy link
Contributor

Choose a reason for hiding this comment

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

This is surprising to me - is it no longer possible to use the constructor with 3 args?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is ~impossible to create a correct Snapshot other than "the empty snapshot" by hand, because you need assistance computing the correct Digest for the files. Consequently, that was the only call to the Snapshot constructor on the Python side.

@stuhood
Copy link
Member Author

stuhood commented Dec 17, 2020

How did you identify this as a candidate for optimization?

In every profile that I look at, lock contention (on the GIL and elsewhere) shows up as our largest bottleneck. While there is more to do around optimizing our locking, the only way to reduce the GIL time is to interact with it less (which in some cases might mean holding it for a longer period rather than acquiring it N times).

@Eric-Arellano
Copy link
Contributor

In every profile that I look at, lock contention (on the GIL and elsewhere) shows up as our largest bottleneck

While we're unlikely to do it, I am still curious how much faster Pants would be if it were purely implemented in Rust. I wonder if it would be feasible to someday expose the plugin API via Rust. (Ack that it would be substantially less accessible, and likely not worth it.)

@stuhood stuhood merged commit 0bf6ac6 into pantsbuild:master Dec 17, 2020
@stuhood stuhood deleted the stuhood/snapshot-to-rust branch December 17, 2020 18:23
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