Release the GIL during evaluation, and decide on free-threaded (cp314t) support
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 42/100
Rechercherichtung
Beginne bei evaluate() und Program.execute() und führe anschließend compile_execute_benchmark.py aus, um den detach/attach-Overhead anhand des angegebenen Schwellenwerts zu messen. Prüfe Context, die gemeinsame stdlib Env und den per-Context-Cache auf Sicherheit bei free-threaded Ausführung und untersuche die maturin-action CI-Matrix. Als erledigt gilt die Aufgabe, wenn die nebenläufige Auswertung durch Tests abgedeckt ist, die Wahl der GIL-Freigabe per Benchmark evaluiert wurde und cp314t-Wheels enthalten sind, falls dies unterstützt wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Problem
evaluate() and Program.execute() hold the GIL for the entire Rust-side evaluation. A Python program that evaluates CEL from several threads therefore serialises on the interpreter even though the work is pure Rust once the context has been converted. This matters for the policy-engine style of use (many rules × many requests) that the README leads with.
Proposal
- Release the GIL around
program.execute()withpy.detach(|| ...)(PyO3 0.29's spelling ofallow_threads). The pieces already have the right bounds:cel::Programis a plain AST,cel::Context<'static>isSend + Sync(itsVal,FunctionandVariableResolvertraits all require it), and the Python-callback wrappers already do their ownPython::attach, so a callback simply re-acquires the GIL when it runs. Conversion of the result back to Python happens after re-attaching. - Measure the fixed cost. Detach/attach is on the order of tens of nanoseconds, but a trivial
x + yexecutes in ~0.15 µs, so unconditional detaching could be a visible relative slowdown for tiny expressions while being a large absolute win for anything heavier or for multi-threaded callers. Options, in order of preference:- detach unconditionally if the overhead measures under ~10% on the
compile_execute_benchmark.pycases; - otherwise detach only when the context has no Python functions and no resolver (that's when the evaluation cannot need the GIL), which is cheap to know from the
Context; - an explicit
execute(ctx, release_gil=...)knob is a last resort.
- detach unconditionally if the overhead measures under ~10% on the
- Free-threaded Python. PyO3 0.29 supports the free-threaded build when the module opts in with
#[pymodule(gil_used = false)]. Before doing that, audit:Contextmutators are&mut self(PyO3's borrow checker turns concurrent mutation into an error rather than a data race), the shared stdlibEnvis aLazyLock, and the per-Contextcache proposed in the Context-reuse PR is behind aMutex. Then addcp314twheels to the CI matrix (maturin-action needs the interpreter listed explicitly;--find-interpreterwon't pick it up).
Non-goals
Context itself is documented as not thread-safe for concurrent mutation; that stays. Concurrent evaluation against a shared Context is already fine and is now pinned by tests.
- Vorherrschende Sprache
- Python
- Sterne
- 43
- Forks
- 4
- Ø Merge
- 12 Std. 37 Min.
- Gemergte PRs (30 T.)
- 11
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus hardbyte/python-common-expression-language
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
hardbyte/python-common-expression-language#47 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
hardbyte/python-common-expression-language#57 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
hardbyte/python-common-expression-language#50 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
hardbyte/python-common-expression-language#49 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 45/100
hardbyte/python-common-expression-language#48 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in hardbyte/python-common-expression-language
Ähnliche Issues
-
feedback simulation workshop
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 73/100
githubnext/gh-aw-workshop#4455 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Triage 🩺
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag
-
[BUG] Container scenario crashes without expected_recovery_time, kube DNS example uses retry_waitOffenneeds-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
krkn-chaos/krkn#1627 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
NousResearch/hermes-agent#136483 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 1 Tag