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] Make GIL usage explicit for session_poll_workunits #13609

Merged
merged 3 commits into from
Nov 14, 2021

Conversation

Eric-Arellano
Copy link
Contributor

@Eric-Arellano Eric-Arellano commented Nov 13, 2021

Prework for #13526. We were reacquiring the GIL directly inside py.allow_threads(||). Rust-cpython allows that, but PyO3 does not. (PyO3 has the benefit of instilling much stronger confidence in reasoning when the GIL is held or not.)

We can easily work around this by having WorkunitStore.with_latest_workunits return Vec<Workunit> instead of &[Workunit]. No new clones are happening! We already were making this Vec. Only now we move the value out, rather than referencing it via a closure passed in as a callback.

That change allows for operating on the Vec<Workunit> safely outside of the py.allow_threads(||) to convert it into the FFI boundary.

Benchmark

These benchmarks use the Toolchain BuildSense plugin + anonymous telemetrics streaming workunit handlers.

No pantsd

Before:

❯ hyperfine -w 1 -r 10 './pants -ldebug --no-pantsd list ::'
  Time (mean ± σ):      4.611 s ±  0.206 s    [User: 2.940 s, System: 0.474 s]
  Range (min … max):    4.419 s …  5.153 s    10 runs

After:

❯ hyperfine -w 1 -r 10 './pants -ldebug --no-pantsd list ::'
  Time (mean ± σ):      4.655 s ±  0.113 s    [User: 2.975 s, System: 0.509 s]
  Range (min … max):    4.430 s …  4.827 s    10 runs

Pantsd

Before:

❯ hyperfine -w 1 -r 10 './pants -ldebug --concurrent --pantsd list ::'
  Time (mean ± σ):      2.641 s ±  0.021 s    [User: 2.026 s, System: 0.323 s]
  Range (min … max):    2.602 s …  2.670 s    10 runs

After:

❯ hyperfine -w 1 -r 10 './pants -ldebug --concurrent --pantsd list ::'
  Time (mean ± σ):      2.651 s ±  0.023 s    [User: 2.036 s, System: 0.334 s]
  Range (min … max):    2.611 s …  2.693 s    10 runs

[ci skip-build-wheels]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano enabled auto-merge (squash) November 14, 2021 00:15
@Eric-Arellano Eric-Arellano merged commit 996ff41 into pantsbuild:main Nov 14, 2021
@Eric-Arellano Eric-Arellano deleted the latest-workunits branch November 14, 2021 01:29
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.

2 participants