Release the GIL during evaluation, and decide on free-threaded (cp314t) support
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 42/100
Direzione di ricerca
Inizia da evaluate() e Program.execute(), quindi esegui compile_execute_benchmark.py per misurare l’overhead di detach/attach rispetto alla soglia indicata. Verifica la sicurezza di Context, della stdlib Env condivisa e della cache per-Context in modalità free-threaded, e ispeziona la matrice CI di maturin-action. Il lavoro è completato quando la valutazione concorrente è coperta dai test, la scelta del rilascio del GIL è stata valutata con un benchmark e le wheels cp314t sono incluse se supportate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 43
- Fork
- 4
- Merge medio
- 9h 57m
- PR unite (30g)
- 14
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di hardbyte/python-common-expression-language
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
-
enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 45/100
Tutte le issue di hardbyte/python-common-expression-language
Issue simili
-
Add: hunch Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
AbdelStark/awesome-typesafe#104 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
DiamondLightSource/dodal#2211 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
openml/openml-python#1749 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
sipyourdrink-ltd/bernstein#6191 ·