Run pants under free threaded python#23477
Conversation
c68208d to
d3a9c73
Compare
|
@cburroughs Risk is close to none afaik, it is mostly a pyo3 compat (meaning we couldnt build it) issue. If we are allowed to assume pants is ran as a scie we defined, the internal 3rd party lockfile does the rest. I think that is ok, building a pants dist and targeting a different python would be highly special usecase. If a plugin uses native deps in rule code that could bite them iff there is no 3.14t wheels for them. |
6a60274 to
b03a612
Compare
|
Pretty substantial (and consequential) change - so I tacked on a bunch of reviewers |
|
Once #23482 is in this will be rebased and the pex binary will again be stripped. Edit: Done. |
|
General review comments:
|
We could vendor release versions with t-suffixes to make it target free-threaded? I'm doubtful of the value to be honest, but that'd be simple enough implementation wise (but requires CI/CD work). I'd prefer opt-out though. I dont want to treat this as a scary change when it isnt, but I will also not claim 0 impact across all plugin code. For the first comment: Yes, easily split. Each commit ~stands on its own already so I can do that branch-ectomy with ~0 effort. |
So like everything in software engineering, my view is "it depends." My preference here is that we not introduce a one way version gate on users when there is no one dedicated to fixing issues for them in a timely manner. I'd rather avoid users being potentially stuck on 2.32 or lower versions with no way to consume all of the other fixes Pants has in 2.33 unrelated to free-threading. So how much more complex would it be to release a free-threading version of Pants alongside the GIL version? The main artifact is the engine's shared library ( My view really depends on just how much additional work the CI/CD & release changes would be.
Opt-out is fine. The concern for me is having the ability to control adoption of the change with some sort of flag versus forcing users to stay on a prior versions because there is no escape hatch from this change. I submit that Incremental adoption with an escape hatch makes for a better user experience. |
You used specific version numbers so I'll just clarify that I do not think this is a 2.33.x change but rather a 2.34.x feature. The point is of course still valid. I'm not sure I agree that this is a strong case for pants and free threading though, we have a patch-version series for fixes and we vendor a binary. We can choose to only release free threading and address eventual bugs. Because it will be bugs, users being "stuck" will be on some flaky CI-runs surfacing races we missed, most likely. Unless of course there is ABI-incompatible user plugins out there.
I dont know exactly, the main effort is figuring that out, and is the counterweight in terms of value I was refering to. |
|
Now I know some more - It'd have to be a separate pants.toml field to not mess with PEP440 compat, but otherwise it goes:
Essentially a question of if we're okay to publish 2x scies. |
afe6389 to
45d78c2
Compare
@tdyas 1 is now done. See the list in the pull request description. |
45d78c2 to
ec295f5
Compare
|
I just want to point out that not everyone uses a scie. We use the big monolithic binaries that are shipped in the release. So please make sure to build an ft version of that as well. |
To make sure I have this right, what from https://github.com/pantsbuild/pants/releases/tag/release_2.32.1 do you use? Colloquially If I head "big monolithic binaries" I would think of the scies there (ex: |
|
We actually don't need to ship multiple scies/versions I think, the free-threaded Python builds support re-enabling the GIL with the |
That doesnt cover ABI mismatch in user-written plugins third party deps, which is imo the strongest argument for a non free-threaded variant. That said, PYTHON_GIL does work and will launch the pants daemon with GIL enabled under free-threaded. It's a bit fickle though, the daemon doesnt pick it up mid run. |
Yes, sorry. I mis-spoke. We don't use scie-pants. |
09b1a73 to
6c14cf3
Compare
|
All pre-requisite pull requests are now in. That means this PR now contains the switch and CI/CD change. Since @cburroughs cut 2.33.x I believe there's not much else than deciding on how we ship it.
So the UX I am proposing herein is thus:
We can then decide which future version we stop building wheels and binaries, because that is when backwards-compat breaks. We can choose to do that never. Since skimming release notes might lead to users thinking PANTS_FREE_THREADED=true is the only thing to configure to get free-threaded I propose we warn at bootstrap time for scie environs.
Off-by-default when scie-pants is updated is the alternative. I like it less because I want to shed the GIL and keep the performance landscape un-parametrized. Free-threaded is so much faster. |
Don't those plugins need to be updated anyway whenever the Python version Pants uses is upgraded? Though I'm guessing most third-party deps with native components provide wheels for multiple GIL-bound Python versions but not necessarily for free-threaded Python. So, fair! |
|
I've decided to additionally open #23514, which should be merged before this. |
23752a3 to
d84668a
Compare
Shaves of about 0.1s startup time. The second commit is 1. Preparatory work for when source plugins are imported in parallell, regular sequential import leaves perf on the table 2. If the python backend is not used, in which case importing pex-rules is wasted work. Not sure if those users exists, though. I intend to introduce paralllel backend imports after #23477. I do not think this conflicts in spirit with #21991. It does conflict in direction with a comment here: #11568, however I find #10360 to have resolved/obsoleted the motivation for the bootstrap scheduler there as well.
d84668a to
57ce810
Compare
Like pants_version, the option is consumed by the scie-pants launcher, which picks between the cp314t and cp314 distributions of a release. PANTS_FREE_THREADED overrides the config value.
The wheel build jobs are parametrized over the two interpreter abis. Wheel tags and PEX asset names already derive from sys.abiflags.
df57f43 to
1c1496a
Compare
Bounds memory growth observed by test_pantsd_memory_usage that otherwise is only reclaimed after >10s
1c1496a to
cb73149
Compare
Switches Pants' own runtime to free-threaded CPython and makes the engine and
Pants' Python code thread-safe without the GIL.
This has been validated as running without error in my companies CI, and nets great speedups.
Most important callouts:
this, every
Python::attachcycle tears down the thread state, and on 3.14tthat abandons the thread's mimalloc heaps. Created per tokio thread, torn down in
on_thread_stop(blockingthreads are recycled, so the state must not leak per thread creation).
I used #23437 as a launching point.
I have on speculation set this as shipping in 2.34.x, as I believe 2.33 is too far along the dev-cycles. But I also do not see any reason to delay further.
Blocks pantsbuild/scie-pants#541
Edit:
This branch now serves as proof of green CI of the accumulation of changes, and will be rebased as its parts are accepted incrementally:
Edit2:
Now that all pre-requisites are in, this PR contains CI/CD changes and the new PANTS_FREE_THREADED option.
Current proposal for consumer UX is
pants_free_threadedfalsecp314(GIL 3.14)truecp314(GIL 3.14)cp314t(free-threaded)falsecp314(GIL 3.14)truecp314t(free-threaded)…-cp314true…-cp314tfalseThis PR is coupled to pantsbuild/scie-pants#541.