<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">I think the detail that was missing is
you need to add the `#cython: fast_gil = True` to enable it.</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">For me:</div>
<div class="moz-cite-prefix">Python 3.9 and 3.10 are basically
identical (on master)<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><span style="font-family:monospace"><span
style="color:#000000;background-color:#ffffff;">**test_gil_already_held**
</span><br>
with fast_gil
<br>
Running the test...
<br>
took 0.175062894821167
<br>
without
<br>
Running the test...
<br>
took 0.10976791381835938
<br>
<br>
**test_gil_released**
<br>
with fast_gil
<br>
Running the test...
<br>
took 0.583066463470459
<br>
without
<br>
Running the test...
<br>
took 0.5824759006500244<br>
</span></div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">test_gil_already_held is noticably
faster with fast_gil.</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">For Python 3.11:</div>
<div class="moz-cite-prefix">I get the crash in 0.29.x if I try to
run using fast_gil. No defines are needed to get that...</div>
<div class="moz-cite-prefix">On master:<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><span style="font-family:monospace"><span
style="color:#000000;background-color:#ffffff;">**test_gil_already_held**
</span><br>
with fast_gil
<br>
Running the test...
<br>
took 0.17254948616027832
<br>
without
<br>
Running the test...
<br>
took 0.10958600044250488
<br>
<br>
**test_gil_released**
<br>
with fast_gil
<br>
Running the test...
<br>
took 0.5791811943054199
<br>
without
<br>
Running the test...
<br>
took 0.5597968101501465<br>
</span></div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Note that "without fastgil" is now as
fast as "fastgil" used to be. As fastgil is now slower. This is
reproducible.</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">On Python 3.12 on master they're
identical by default (which makes sense since I think we disable
it). Defining -DCYTHON_FAST_GIL brings us back to roughly the same
as 3.11 (i.e. now slower).</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">So my conclusion is that from 3.11
onwards Python sped up their own GIL handling to about the same as
we used to have, and fastgil has turned into a pessimization.</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">David<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">On 19/09/2023 11:58, Lisandro Dalcin
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAEcYPwBkRZwyO+zgOdRU3E0GM1h4OjjXpAUNNFranRCNhWgWwQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div>
<div>Disclaimer: I may be doing something wrong, I did not put
a lot of effort into it. </div>
<div>With the microbenchmark that was offered in the GH issue,
I see little difference.</div>
</div>
<div>Use the attached zip file to reproduce yourself. <br>
</div>
<div>Change tox.ini to "cython<3" to try 0.29.x. </div>
<div>BTW, in the 0.29.x case, I see no compilation error as
claimed in the GH issue.</div>
<div><br>
</div>
<font face="monospace">$ ./run.sh <br>
CFLAGS=-g0 -Ofast -DCYTHON_FAST_GIL=0<br>
Running test_gil_already_held ... took 0.08735537528991699<br>
Running test_gil_released ... took 0.6329536437988281<br>
py37: OK ✔ in 3.57 seconds<br>
Running test_gil_already_held ... took 0.09007453918457031<br>
Running test_gil_released ... took 0.4598276615142822<br>
py38: OK ✔ in 3.19 seconds<br>
Running test_gil_already_held ... took 0.10935306549072266<br>
Running test_gil_released ... took 0.4512367248535156<br>
py39: OK ✔ in 3.25 seconds<br>
Running test_gil_already_held ... took 0.09970474243164062<br>
Running test_gil_released ... took 0.46637773513793945<br>
py310: OK ✔ in 3.21 seconds<br>
Running test_gil_already_held ... took 0.08569073677062988<br>
Running test_gil_released ... took 0.46811795234680176<br>
py311: OK ✔ in 3.22 seconds<br>
Running test_gil_already_held ... took 0.15221118927001953<br>
Running test_gil_released ... took 0.2246694564819336<br>
py37: OK (3.57 seconds)<br>
py38: OK (3.19 seconds)<br>
py39: OK (3.25 seconds)<br>
py310: OK (3.21 seconds)<br>
py311: OK (3.22 seconds)<br>
pypy3.9: OK (5.24 seconds)<br>
congratulations :) (21.71 seconds)<br>
CFLAGS=-g0 -Ofast -DCYTHON_FAST_GIL=1<br>
Running test_gil_already_held ... took 0.08835673332214355<br>
Running test_gil_released ... took 0.6265637874603271<br>
py37: OK ✔ in 1.42 seconds<br>
Running test_gil_already_held ... took 0.09030938148498535<br>
Running test_gil_released ... took 0.456279993057251<br>
py38: OK ✔ in 1.17 seconds<br>
Running test_gil_already_held ... took 0.10986089706420898<br>
Running test_gil_released ... took 0.45894527435302734<br>
py39: OK ✔ in 1.2 seconds<br>
Running test_gil_already_held ... took 0.10107588768005371<br>
Running test_gil_released ... took 0.5052204132080078<br>
py310: OK ✔ in 1.21 seconds<br>
Running test_gil_already_held ... took 0.08566665649414062<br>
Running test_gil_released ... took 0.4581136703491211<br>
py311: OK ✔ in 1.13 seconds<br>
Running test_gil_already_held ... took 0.15286779403686523<br>
Running test_gil_released ... took 0.22533607482910156<br>
py37: OK (1.42 seconds)<br>
py38: OK (1.17 seconds)<br>
py39: OK (1.20 seconds)<br>
py310: OK (1.21 seconds)<br>
py311: OK (1.13 seconds)<br>
pypy3.9: OK (1.64 seconds)<br>
congratulations :) (7.81 seconds)<br>
</font>
<div><br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, 19 Sept 2023 at 10:09,
Stefan Behnel <<a href="mailto:stefan_ml@behnel.de"
moz-do-not-send="true" class="moz-txt-link-freetext">stefan_ml@behnel.de</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I've seen reports that Cython's "FastGIL" implementation
(which basically <br>
keeps the GIL state in a thread-local variable) is no longer
faster than <br>
CPython's plain GIL implementation in recent Python 3.x
versions. <br>
Potentially even slower. See the report in<br>
<br>
<a href="https://github.com/cython/cython/issues/5703"
rel="noreferrer" target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://github.com/cython/cython/issues/5703</a><br>
<br>
It would be helpful to get user feedback on this.<br>
<br>
If you have GIL-heavy Cython code, especially with nested <br>
with-nogil/with-gil sections across functions, and a benchmark
that <br>
exercises it, could you please run the benchmark with and
without the <br>
feature enabled and report the results?<br>
<br>
You can add "-DCYTHON_FAST_GIL=0" to your CFLAGS to disabled
it (and "=1" <br>
to enable it explicitly). It's enabled by default in CPython
3.6-3.11 (but <br>
disabled in Cython 0.29.x on Python 3.11).<br>
<br>
Thanks,<br>
Stefan<br>
_______________________________________________<br>
cython-devel mailing list<br>
<a href="mailto:cython-devel@python.org" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">cython-devel@python.org</a><br>
<a
href="https://mail.python.org/mailman/listinfo/cython-devel"
rel="noreferrer" target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://mail.python.org/mailman/listinfo/cython-devel</a><br>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
<span class="gmail_signature_prefix">-- </span><br>
<div dir="ltr" class="gmail_signature">
<div dir="ltr">
<div>Lisandro Dalcin<br>
============<br>
Senior Research Scientist<br>
Extreme Computing Research Center (ECRC)<br>
King Abdullah University of Science and Technology (KAUST)<br>
<a href="http://ecrc.kaust.edu.sa/" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">http://ecrc.kaust.edu.sa/</a><br>
</div>
</div>
</div>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
cython-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cython-devel@python.org">cython-devel@python.org</a>
<a class="moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/cython-devel">https://mail.python.org/mailman/listinfo/cython-devel</a>
</pre>
</blockquote>
<p><br>
</p>
</body>
</html>