{"id":329454,"date":"2023-05-29T16:18:00","date_gmt":"2023-05-29T16:18:00","guid":{"rendered":"http:\/\/itteacheritfreelance.hk\/wordpress\/?guid=60d61c990fc2ecdcaa05b17fff362ea9"},"modified":"2023-05-29T16:18:00","modified_gmt":"2023-05-29T16:18:00","slug":"the-python-language-summit-2023-making-the-global-interpreter-lock-optional","status":"publish","type":"post","link":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/2023\/05\/29\/the-python-language-summit-2023-making-the-global-interpreter-lock-optional\/","title":{"rendered":"The Python Language Summit 2023: Making the Global Interpreter Lock Optional"},"content":{"rendered":"<p class=\"syndicated-attribution\"><meta name= \\\"keywords \\\" content= \\\"\u96fb\u5b50\u8a08\u7b97\u6a5f, \u6559\u80b2, IT \u96fb\u8166\u73ed,\u96fb\u8166\u88dc\u7fd2\uff0c \u96fb\u8166\u73ed\uff0c \u5bb6\u6559\uff0c \u79c1\u4eba\u8001\u5e2b\uff0c \u8cc7\u8a0a\u6280\u8853\uff0c \u7a0b\u5e8f\u8a2d\u8a08\uff0c \u96fb\u5b50\u8a08\u7b97\u6a5f\uff0c \u904a\u6232\uff0c \u860b\u679c\uff0c \u96fb\u5f71\uff0c \u8a08\u7b97\u6a5f\uff0c\u7de8\u78bc\uff0c Java\uff0c C\/C++\uff0c JavaScript\uff0c PHP\uff0c HTML\uff0c CSS\uff0c MySQL\uff0c mobile\uff0c Android\uff0c \u52d5\u6f2b\uff0c Python\uff0c teacher\uff0c \u88dc\u7fd2\uff0c \u96fb\u8166\u88dc\u7fd2 \u8cc7\u8a0a, \u7535\u5b50\u8ba1\u7b97\u673a, IT ,Game, apple, movie, Computer,student,Java,\u6559\u80b2, ,\u5b66\u751f, \u5b66\u4e60, learn, \u6559\u5b66,  Android, apple,anime, animation, \u4fe1\u606f\u6280\u672f, \u7a0b\u5e8f\u8bbe\u8ba1, \u79fb\u52a8\u7535\u8bdd, \u8cc7\u8a0a\u79d1\u6280,Game, Jeu, Juego,Call Of Duty ,\u4f7f\u547d\u53ec\u559a , \u6e38\u620f, \u7535\u5b50\u6e38\u620f,, \u591a\u4eba\u7535\u5b50\u6e38\u620f, \u7f51\u7edc\u6e38\u620f\uff0conline\uff0conline game, \u624b\u673a\u6e38\u620f, mobile \\\"><\/p>\n<div class=\"markdown-body container-fluid comment-inner comment-enabled\" data-hard-breaks=\"true\" id=\"doc\">The Global Interpreter Lock (\u201cGIL\u201d), is one of the most fundamental parts of how Python works today. It\u2019s also one of the most controversial parts, as it prevents true concurrency between threads \u2013 another way of saying that it\u2019s difficult to run two functions simultaneously while writing pure-Python code.<\/p>\n<p><span>If there\u2019s one blog that really \u201ctook off\u201d after I wrote last year\u2019s coverage on the Python Language Summit, it was <\/span><a href=\"https:\/\/pyfound.blogspot.com\/2022\/05\/the-2022-python-language-summit-python_11.html\" rel=\"noopener\" ><span>my blog on Sam Gross\u2019s proposal to make Python\u2019s Global Interpreter Lock (the \u201cGIL\u201d) optional<\/span><\/a><span>. One week following the publication of my articles, the blog had been viewed nearly 38,000 times; the blog in \u201csecond place\u201d had only been viewed 5,300 times.<\/span><\/p>\n<p><span>Interest in removing the GIL is clear, therefore \u2013 and this year, Gross returned to the <a href=\"https:\/\/pyfound.blogspot.com\/2023\/05\/the-python-language-summit-2023_29.html\" rel=\"nofollow\" >Python Language Summit<\/a> to discuss the development of his plans.<\/span><\/p>\n<h2 class=\"raw\"><span>Dare to dream of a GIL-free world<\/span><\/h2>\n<p><span>Gross started off by giving an update on how work on <\/span><code>nogil<\/code><span> \u2013 Gross\u2019s fork of CPython with the GIL removed \u2013 had progressed over the past year. Gross had been spending the last few months rebasing his fork onto CPython 3.12. As a result, he was now able to give an accurate estimate of how bad the performance costs to single-threaded code would be, if the GIL were removed.<\/span><\/p>\n<p><span>Over the past year, Gross had also written a PEP \u2013 <\/span><a href=\"https:\/\/peps.python.org\/pep-0703\/\" rel=\"noopener\" ><span>PEP 703<\/span><\/a><span> \u2013 which, following the Language Summit, was <\/span><a href=\"https:\/\/github.com\/python\/steering-council\/issues\/188\" rel=\"noopener\" ><span>submitted to the Steering Council for their consideration<\/span><\/a><span> on May 12. If the PEP is accepted by the Steering Council, a version of Python with the GIL disabled could be available as soon as Python 3.13. (To discuss the ideas in the PEP, head to <\/span><a href=\"https:\/\/discuss.python.org\/t\/pep-703-making-the-global-interpreter-lock-optional-3-12-updates\/26503\/1\" rel=\"noopener\" ><span>the thread on discuss.python.org<\/span><\/a><span>.)<\/span><\/p>\n<p><span>Gross reported that the latest version of <\/span><code>nogil<\/code><span> was around 6% slower on single-threaded code than the CPython <\/span><code>main<\/code><span> branch, and that he was confident that the performance overhead could be reduced even further, possibly to nearly 0%. Most of the overhead was due to reference counting and changes that had been required to the operation of CPython\u2019s new-in-3.11 <\/span><a href=\"https:\/\/pyfound.blogspot.com\/2022\/05\/the-2022-python-language-summit_2.html\" rel=\"noopener\" ><span>specialising adaptive interpreter<\/span><\/a><span>. With multiple threads, the performance overhead was around 8%.<\/span><\/p>\n<p><span><br \/><\/span><\/p>\n<\/p>\n<table align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"tr-caption-container\" style=\"margin-left: auto; margin-right: auto;\">\n<tbody>\n<tr>\n<td style=\"text-align: center;\"><a href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhz0cEgI5ArFR9lfrczf74Z1y3C536LXYM7iW8WJKi3G_A_Usgp-Bhl8tbOqL7lCkZgpa4Nod76W7FRbSAZ6jwekyynJXd7CDYTSnoilbuGTvRpgvjkYpAMuTBCUwQYeFMpOKsRafkrus1HHzPUC6RFtS0Zu0okF4UVZyeJj_NnQD1C4ck\/s1025\/Sam%20Gross%20picture.png\" style=\"margin-left: auto; margin-right: auto;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" data-original-height=\"585\" data-original-width=\"1025\" height=\"183\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhz0cEgI5ArFR9lfrczf74Z1y3C536LXYM7iW8WJKi3G_A_Usgp-Bhl8tbOqL7lCkZgpa4Nod76W7FRbSAZ6jwekyynJXd7CDYTSnoilbuGTvRpgvjkYpAMuTBCUwQYeFMpOKsRafkrus1HHzPUC6RFtS0Zu0okF4UVZyeJj_NnQD1C4ck\/s320\/Sam%20Gross%20picture.png\" width=\"320\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td class=\"tr-caption\" style=\"text-align: center;\">A slide from Gross&#8217;s talk<br \/>(numbers indicate the per-thread overhead)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<p><span>Having rebased onto Python 3.12, Gross was also able to give an estimate on the extent of the code changes that would be required to CPython, were <\/span><code>nogil<\/code><span> to be accepted. Excluding generated files, Gross reported that around 15,000 lines of code would need to be changed. There would also need to be some alterations to <\/span><a href=\"https:\/\/github.com\/microsoft\/mimalloc\" rel=\"noopener\" ><span>mimalloc<\/span><\/a><span>, which <\/span><code>nogil<\/code><span> depends on \u2013 but Gross was hopeful that these would be accepted to mimalloc itself, reducing the need for CPython to maintain mimalloc patches in its codebase.<\/span><\/p>\n<p><span>Some audience members expressed concern about the prospect of \u201c<\/span><code>#ifdef<\/code><span> hell\u201d across the code base, to account for the two possible CPython build options. However, Gross countered that most of the changes required could be made unconditionally without resorting to <\/span><code>#ifdef<\/code><span>s, since the changes were simply no-ops with the GIL enabled.<\/span><\/p>\n<p><span>The plan for <\/span><code>nogil<\/code><span> remains that it would be enabled via a compile-time flag, named <\/span><code>--disable-gil<\/code><span>. Third-party C extensions would need to provide separate wheels for GIL-disabled Python.<\/span><\/p>\n<h2 class=\"raw\"><span>GIL gotta go<\/span><\/h2>\n<p><span>Last year, it felt as though Gross\u2019s proposal was met with a certain degree of excitement, but also a certain degree of scepticism. It was thrilling to see how far <\/span><code>nogil<\/code><span> had come, but there was a certain amount of frustration in the room at the lack of a concrete plan for where to go next.<\/span><\/p>\n<p><span>This year, it felt like the proposal was greeted much more warmly. Gross had come to the summit with a far more clearly defined roadmap for how we might get to <\/span><code>nogil<\/code><span>, and had taken the time to put together detailed estimates of the performance impact and the extent of the code changes.<\/span><\/p>\n<blockquote>\n<p><span>\u201cThank you for doing this\u2026 now we have something we can actually consider!\u201d<\/span>&nbsp;<\/p>\n<\/blockquote>\n<blockquote>\n<p>&#8212;<i> Brandt Bucher, CPython Core Developer<\/i><\/p>\n<\/blockquote>\n<p><span>Attendees at the Language Summit were also impressed at how low the performance overhead of <\/span><code>nogil<\/code><span> was, although Mark Shannon commented that he thought the numbers might be \u201ca slight underestimate\u201d. Gross explained that he had managed to achieve a 2-3% speedup by optimising for the case where only a single thread was active. Even in multithreaded programs, he explained, this provided a performance boost, since even in multithreaded code, it was often the case that only a single thread would be attempting to access an object at any given point in time.<\/span><\/p>\n<p><span>Larry Hastings expressed concern that <\/span><code>nogil<\/code><span> might make debugging code harder; Gross responded that there was some impact on debuggability, but that it wasn\u2019t too bad, in his opinion. Pablo Galindo Salgado, release manager for Python 3.10 and 3.11, expressed concern that <\/span><code>nogil<\/code><span> could also make implementing debuggers trickier \u2013 but commented that \u201cit might be worth the price\u201d anyway.<\/span><\/p>\n<p><span>Another point of discussion was the changes Gross had made to <\/span><a href=\"https:\/\/peps.python.org\/pep-0659\/\" rel=\"noopener\" ><span>the specialising adaptive interpreter<\/span><\/a><span> in the <\/span><code>nogil<\/code><span> fork. In order for the specialisations to work with the GIL disabled, Gross had had to guard the adaptive specialisations to the bytecode behind a lock. As well as this, each thread had been limited to a single specialisation of any given bytecode; with the GIL enabled, the adaptive interpreter can respecialise bytecode multiple times. Gross commented that he thought it would probably be possible to allow multiple specialisations of bytecode in multithreaded code, but that this would require further investigation. His current solution was the simplest one he had found, for now.<\/span><\/p>\n<\/div>\n\n<p class=\"syndicated-attribution\"><figure class= \\\"wp-block-image alignnone \\\"><img src= \\\"http:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-content\/uploads\/2016\/05\/logo2-2.png\\\" alt=\\\"IT\u96fb\u8166\u88dc\u7fd2 java\u88dc\u7fd2 \u70ba\u5927\u5bb6\u914d\u5c0d\u96fb\u8166\u88dc\u7fd2,IT freelance, \u79c1\u4eba\u8001\u5e2b, PHP\u88dc\u7fd2,CSS\u88dc\u7fd2,XML,Java\u88dc\u7fd2,MySQL\u88dc\u7fd2,graphic design\u88dc\u7fd2,\u4e2d\u5c0f\u5b78ICT\u88dc\u7fd2,\u4e00\u5c0d\u4e00\u79c1\u4eba\u88dc\u7fd2\u548cFreelance\u81ea\u7531\u5de5\u4f5c\u914d\u5c0d\u3002\\\"\/><figcaption>\u7acb\u523b\u8a3b\u518a\u53ca\u5831\u540d\u96fb\u8166\u88dc\u7fd2\u8ab2\u7a0b\u5427!<\/figcaption><\/figure>\r\n<\/br>Find A Teacher Form:\r\n<\/br>https:\/\/docs.google.com\/forms\/d\/1vREBnX5n262umf4wU5U2pyTwvk9O-JrAgblA-wH9GFQ\/viewform?edit_requested=true#responses\r\n<\/br><\/br>Email:\r\n<\/br>public1989two@gmail.com<br><br><br><br><br><br><br>\r\n<a href=www.itsec.hk style=color:#FFFFFF;>www.itsec.hk<\/a><br>\r\n<a href=\\\"www.itsec.vip\\\" style=color:#FFFFFF;>www.itsec.vip<\/a><br>\r\n<a href=\\\"www.itseceu.uk\\\" style=color:#FFFFFF;>www.itseceu.uk<\/a><br><\/p>","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>The Global Interpreter Lock (\u201cGIL\u201d), is one of the most fundamental parts of how Python works today. It\u2019s also one of the most controversial parts, as it prevents true concurrency between threads \u2013 another way of saying that it\u2019s difficult to run two &#8230;<\/p>\n<\/div>","protected":false},"author":2053,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"The Python Language Summit 2023: Making the Global Interpreter Lock Optional - ITTeacherITFreelance.hk","description":"The Global Interpreter Lock (\u201cGIL\u201d), is one of the most fundamental parts of how Python works today. It\u2019s also one of the most controversial parts, as it preven"},"footnotes":""},"categories":[10700],"tags":[],"_links":{"self":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/329454"}],"collection":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/2053"}],"replies":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=329454"}],"version-history":[{"count":1,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/329454\/revisions"}],"predecessor-version":[{"id":329455,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/329454\/revisions\/329455"}],"wp:attachment":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=329454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=329454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=329454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}