-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
Conversation
# 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]
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.
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: ... |
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.
This is surprising to me - is it no longer possible to use the constructor with 3 args?
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.
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.
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). |
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.) |
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 RustDigest
instance.Solution
In two commits: port
fs.Snapshot
to Rust, and optimize the conversion of aPyDigest
to aDigest
.Result
6% faster runs of
./pants dependencies --transitive ::
.[ci skip-build-wheels]