René's URL Explorer Experiment


Title: Enable building both an interpreter that statically links libpython and a shared library too · Issue #133312 · python/cpython · GitHub

Open Graph Title: Enable building both an interpreter that statically links libpython and a shared library too · Issue #133312 · python/cpython

X Title: Enable building both an interpreter that statically links libpython and a shared library too · Issue #133312 · python/cpython

Description: Feature or enhancement Proposal: Right now, if you ./configure --enable-shared, you get a bin/python3 that uses libpython3.x.so, and if you leave the option out (or explicitly ./configure --disable-shared), you get a bin/python3 that sta...

Open Graph Description: Feature or enhancement Proposal: Right now, if you ./configure --enable-shared, you get a bin/python3 that uses libpython3.x.so, and if you leave the option out (or explicitly ./configure --disable...

X Description: Feature or enhancement Proposal: Right now, if you ./configure --enable-shared, you get a bin/python3 that uses libpython3.x.so, and if you leave the option out (or explicitly ./configure --disable...

Opengraph URL: https://github.com/python/cpython/issues/133312

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Enable building both an interpreter that statically links libpython and a shared library too","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nRight now, if you `./configure --enable-shared`, you get a bin/python3 that uses libpython3.x.so, and if you leave the option out (or explicitly `./configure --disable-shared`), you get a bin/python3 that statically links libpython into itself and no libpython3.x.so.\n\nIt's very useful to have a libpython3.x.so available for applications that need it because they embed Python in various ways. At the same time, there are some performance speedups from not having the extra layer of indirection in bin/python3. It would be useful to have a build option that gets you a best-of-both-worlds build (at the cost of more disk space): a bin/python3 that statically links libpython _and_ a libpython3.x.so for other binaries that might need it.\n\nAs a data point, this is useful enough that Debian currently does this in their Python package in a roundabout way: they build Python twice, once with `--enable-shared` and once without, and they then assemble the package by taking the libpython3.x.so from the former build and everything else from the latter build. (See, for instance, [the debian/rules file for Debian python3 3.13.3-2](https://salsa.debian.org/cpython-team/python3/-/blob/3.13.3-2/debian/rules?ref_type=tags): in lines 395-412 they do a `--enable-shared` build into `$(buildd_shared)`, in lines 438-450 they do a non-shared build into `$(buildd_static)`, in line 878 they do a `make -C $(buildd_static) install`, and in lines 939-940 they copy libpython3.x.so.1.0 out of `$(buildd_shared)`.)\n\nThere is not a particular need to do two separate builds, since the behavior changes from `--enable-shared` happen after most of the compilation has happened, in generating the final binaries. All that needs to happen is that the Makefile builds the interpreter binary the way it would for a static build, and also builds the shared library as it would if it were a dependency of the interpreter.\n\nI have implemented this change and will open a PR momentarily.\n\nDetails on the performance benefits: while this is always a little bit of folklore, I can point to three specific things. First, Debian made this change in 2002 based on a reported 50% speedup/penalty in https://bugs.debian.org/131813 (it is interesting that the maintainer was not able to reproduce the problem, but the end user nonetheless saw the benefit from the change).\n\nSecond, there is obviously a benefit from loading one fewer file at process startup, though the impact is most obvious when your files are not in cache and process startup dominates your runtime. I see a ~15% penalty from `python3 -c True` on an AWS t2.medium VM from using the shared library:\n\n```\nubuntu@ip-172-16-0-59:~$ hyperfine -L dir b,c '{dir}/python/install/bin/python3 -c True' --prepare 'echo 3 | sudo tee /proc/sys/vm/drop_caches'\nBenchmark 1: b/python/install/bin/python3 -c True\n  Time (mean ± σ):     183.1 ms ±   7.5 ms    [User: 14.9 ms, System: 16.4 ms]\n  Range (min … max):   173.1 ms … 195.1 ms    10 runs\n \nBenchmark 2: c/python/install/bin/python3 -c True\n  Time (mean ± σ):     155.8 ms ±   7.4 ms    [User: 14.3 ms, System: 16.6 ms]\n  Range (min … max):   142.5 ms … 166.9 ms    11 runs\n \nSummary\n  c/python/install/bin/python3 -c True ran\n    1.17 ± 0.07 times faster than b/python/install/bin/python3 -c True\n```\n\nFinally, in a free-threaded build, running the old \"pystones\" benchmark in multiple threads is about 10% slower with the shared library:\n\n```\nubuntu@ip-172-16-0-59:~/ft$ hyperfine -L dir b,c '{dir}/python/install/bin/python3 ~/threadstone.py'\nBenchmark 1: b/python/install/bin/python3 ~/threadstone.py\n  Time (mean ± σ):      2.208 s ±  0.064 s    [User: 3.722 s, System: 0.545 s]\n  Range (min … max):    2.155 s …  2.379 s    10 runs\n \nBenchmark 2: c/python/install/bin/python3 ~/threadstone.py\n  Time (mean ± σ):      1.993 s ±  0.052 s    [User: 3.353 s, System: 0.487 s]\n  Range (min … max):    1.921 s …  2.122 s    10 runs\n \nSummary\n  c/python/install/bin/python3 ~/threadstone.py ran\n    1.11 ± 0.04 times faster than b/python/install/bin/python3 ~/threadstone.py\n```\n\nwhere `threadstone.py` is\n```python3\nimport pystone\nimport concurrent.futures\nt = concurrent.futures.ThreadPoolExecutor()\nfor i in range(500):\n    t.submit(pystone.pystones, 1000)\nt.shutdown()\n```\nand `pystone.py` is taken from just before 61fd70e05027150b21184c7bc9fa8aa0a49f9601.\n\nThis particular penalty is very understandable. In a shared library, thread-local storage for variables (globals or statics) in that library is allocated dynamically and on demand with the help of a function call to the C runtime that needs to be called whenever you're making an access and don't already have the right pointer cached. In the main executable, thread-local storage can be allocated up front, statically, with a fixed offset from the register that holds the thread-local storage area. So, code that makes heavy use of thread-local storage will perform better if compiled directly into the main binary. (A convenient thing about how ELF handles this is that there is a relocation type for thread-local accesses, and while generated code starts off including the function call to the helper function, the relocation is able to overwrite that function call with effectively no-op instructions if it's being linked into a main executable. So _the same .o file can be used in both cases_ without having to tell the compiler up front if the code is going into a main executable or a shared library, without putting the performance benefits at risk.)\n\nSee more details on the benchmarks, more benchmarks, and the generated assembly code for thread-local storage access in astral-sh/python-build-standalone#592.\n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-133313\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/geofft","@type":"Person","name":"geofft"},"datePublished":"2025-05-02T18:23:27Z","url":"https://github.com/python/cpython/issues/133312"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:fbec9f97-31ca-d2b6-00c4-8a14f9097215
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8708:2023BA:43203A:58AE8B:6B023C4A
html-safe-nonce4561070271cbf0c87d29553be038ed5b084b758bd786bcd29d2ea2e545f7a843
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzA4OjIwMjNCQTo0MzIwM0E6NThBRThCOjZCMDIzQzRBIiwidmlzaXRvcl9pZCI6Ijg5NTkxNDMzOTkwMTUyMDk3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac6fc640a8411924f1d37a5d74564b6cc3a43b57af92c8070fadf0555c4b41d2ac
hovercard-subject-tagissue:3036587818
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/133312/issue_layout
twitter:imagehttps://opengraph.githubassets.com/8fc471fcd8a712e08013a3cc69dd9651b94a628c700849811c76c214af4b17c9/python/cpython/issues/133312
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/8fc471fcd8a712e08013a3cc69dd9651b94a628c700849811c76c214af4b17c9/python/cpython/issues/133312
og:image:altFeature or enhancement Proposal: Right now, if you ./configure --enable-shared, you get a bin/python3 that uses libpython3.x.so, and if you leave the option out (or explicitly ./configure --disable...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamegeofft
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/133312#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F133312
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F133312
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/133312
Reloadhttps://github.com/python/cpython/issues/133312
Reloadhttps://github.com/python/cpython/issues/133312
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/133312
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/133312
Enable building both an interpreter that statically links libpython and a shared library toohttps://github.com/python/cpython/issues/133312#top
buildThe build process and cross-buildhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22build%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/geofft
geoffthttps://github.com/geofft
on May 2, 2025https://github.com/python/cpython/issues/133312#issue-3036587818
the debian/rules file for Debian python3 3.13.3-2https://salsa.debian.org/cpython-team/python3/-/blob/3.13.3-2/debian/rules?ref_type=tags
https://bugs.debian.org/131813https://bugs.debian.org/131813
61fd70ehttps://github.com/python/cpython/commit/61fd70e05027150b21184c7bc9fa8aa0a49f9601
astral-sh/python-build-standalone#592https://github.com/astral-sh/python-build-standalone/pull/592
gh-133312: configure: add --enable-static-libpython-for-interpreter #133313https://github.com/python/cpython/pull/133313
geoffthttps://github.com/geofft
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
on May 2, 2025https://github.com/python/cpython/issues/133312#event-17503359183
geoffthttps://github.com/geofft
on May 2, 2025https://github.com/python/cpython/issues/133312#event-17503477457
pythongh-133312: configure: add --enable-static-libpython-for-interpr…https://github.com/geofft/cpython/commit/68b08bbf06c1b638e1876ba92ced0befa869cb7d
pythongh-133312https://github.com/python/cpython/issues/133312
68b08bbhttps://github.com/geofft/cpython/commit/68b08bbf06c1b638e1876ba92ced0befa869cb7d
AlexWaygoodhttps://github.com/AlexWaygood
buildThe build process and cross-buildhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22build%22
on May 2, 2025https://github.com/python/cpython/issues/133312#event-17504056224
https://github.com/edmorley
edmorleyhttps://github.com/edmorley
on May 19, 2025https://github.com/python/cpython/issues/133312#issuecomment-2891850189
https://bugs.debian.org/131813https://bugs.debian.org/131813
Compile libpython with -fno-semantic-interposition #83161https://github.com/python/cpython/issues/83161
https://fedoraproject.org/wiki/Changes/PythonNoSemanticInterpositionSpeeduphttps://fedoraproject.org/wiki/Changes/PythonNoSemanticInterpositionSpeedup
https://developers.redhat.com/blog/2020/06/25/red-hat-enterprise-linux-8-2-brings-faster-python-3-8-run-speedshttps://developers.redhat.com/blog/2020/06/25/red-hat-enterprise-linux-8-2-brings-faster-python-3-8-run-speeds
https://github.com/geofft
geoffthttps://github.com/geofft
on May 19, 2025https://github.com/python/cpython/issues/133312#issuecomment-2892282970
astral-sh/python-build-standalone#592https://github.com/astral-sh/python-build-standalone/pull/592
pablogsalhttps://github.com/pablogsal
on Apr 14, 2026https://github.com/python/cpython/issues/133312#event-24493732931
gh-133312: configure: add --enable-static-libpython-for-interpreter (#…https://github.com/python/cpython/commit/c88c27b0c1c09c125fe6a5ad78a4d42cf9c3fcd2
gh-133312https://github.com/python/cpython/issues/133312
#…https://github.com/python/cpython/pull/133313
c88c27bhttps://github.com/python/cpython/commit/c88c27b0c1c09c125fe6a5ad78a4d42cf9c3fcd2
ljfphttps://github.com/ljfp
on Apr 25, 2026https://github.com/python/cpython/issues/133312#event-24868340777
pythongh-133312: configure: add --enable-static-libpython-for-interpr…https://github.com/ljfp/cpython/commit/faec76f44b86d1876ccfe876fb90e3eababfdc4d
pythongh-133312https://github.com/python/cpython/issues/133312
faec76fhttps://github.com/ljfp/cpython/commit/faec76f44b86d1876ccfe876fb90e3eababfdc4d
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/133312
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/133312
buildThe build process and cross-buildhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22build%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.