René's URL Explorer Experiment


Title: Use PEP 669 API for cprofile · Issue #103533 · python/cpython · GitHub

Open Graph Title: Use PEP 669 API for cprofile · Issue #103533 · python/cpython

X Title: Use PEP 669 API for cprofile · Issue #103533 · python/cpython

Description: Feature or enhancement Replace the current setprofile mechanism with PEP 669 API for cProfile. Pitch It's faster. Before: Hanoi: 0.342869599997357, 1.4579414000036195, 4.252174587699983 fib: 0.15549560000363272, 0.7588815999988583, 4.880...

Open Graph Description: Feature or enhancement Replace the current setprofile mechanism with PEP 669 API for cProfile. Pitch It's faster. Before: Hanoi: 0.342869599997357, 1.4579414000036195, 4.252174587699983 fib: 0.1554...

X Description: Feature or enhancement Replace the current setprofile mechanism with PEP 669 API for cProfile. Pitch It's faster. Before: Hanoi: 0.342869599997357, 1.4579414000036195, 4.252174587699983 fib: 0....

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Use PEP 669 API for cprofile","articleBody":"# Feature or enhancement\r\n\r\nReplace the current `setprofile` mechanism with PEP 669 API for cProfile.\r\n\r\n# Pitch\r\n\r\nIt's faster.\r\n\r\nBefore:\r\n```\r\nHanoi: 0.342869599997357, 1.4579414000036195, 4.252174587699983\r\nfib: 0.15549560000363272, 0.7588815999988583, 4.88040561907301\r\n\r\nHanoi: 0.33156009999947855, 1.394542599999113, 4.2060024713507635\r\nfib: 0.16397210000286577, 0.7469802000050549, 4.555532313070332\r\n\r\nHanoi: 0.3341937000004691, 1.394005099995411, 4.171248889471747\r\nfib: 0.15704140000161715, 0.7399598000047263, 4.711877250184387\r\n\r\nHanoi: 0.33133889999589883, 1.3821628000005148, 4.171447421409387\r\nfib: 0.15387790000386303, 0.754370700000436, 4.902397940064804\r\n\r\nHanoi: 0.3403002000050037, 1.3969628000049852, 4.105089564991276\r\nfib: 0.15468130000226665, 0.761441399998148, 4.922646758121312\r\n```\r\n\r\nAfter:\r\n```\r\nHanoi: 0.3318088000014541, 1.2147841000041808, 3.661096691826309\r\nfib: 0.15522490000148537, 0.6360437999974238, 4.097562955372092\r\n\r\nHanoi: 0.33085879999998724, 1.1502422000048682, 3.476535005279934\r\nfib: 0.15410060000431258, 0.6056611999956658, 3.9302974808580635\r\n\r\nHanoi: 0.35002540000277804, 1.145935599997756, 3.273864125256799\r\nfib: 0.1540030999967712, 0.5974198000039905, 3.8792712615299036\r\n\r\nHanoi: 0.3338971999983187, 1.1459307999975863, 3.431986851052829\r\nfib: 0.16891020000184653, 0.6197690999979386, 3.6692224625343126\r\n\r\nHanoi: 0.3318254999976489, 1.1875411000000895, 3.578812056362467\r\nfib: 0.1544136999946204, 0.5971600999982911, 3.867274082669449\r\n```\r\n\r\n20%+ speed up for overhead.\r\n\r\nI guess the incentive is not in doubt, but I did have some issues when I implemented it.\r\n\r\n1. There is a very slight backward compatibility issue, or it's more like a design decision. The profiler has to disable its own profiling now.\r\n\r\n```python\r\n# This works on main, but I don't think that's intuitive.\r\npr = cProfile.Profile()\r\npr.enable()\r\npr = cProfile.Profile()\r\npr.disable()\r\n```\r\n\r\nWe can make it work as before, I just think this is not the right way to do it with PEP 669. Because of this, I changed an old (15 years) test in `test_cprofile`.\r\n\r\n2. We need to get the actual c function from the descriptor, for which I used the code in the current legacy tracing. However, `_PyInstrumentation_MISSING` is not exposed so I had to store it locally (keep reading it from `sys` is a bit expensive).\r\n\r\n3. On that matter, are we going to expose some APIs on C? It would be nice if I don't have to get `sys.monitoring` and do stuff from there. We have some defined constants but some APIs could be handy. We may be able to reduce the overhead a bit if we have an interface like `PyEval_SetProfile`.\r\n\r\nAddendum:\r\n\u003cdetails\u003e\r\n\u003csummary\u003e Benchmark Code \u003c/summary\u003e\r\n\r\n```python\r\nimport timeit\r\n\r\nhanoi_setup = \"\"\"\r\nimport cProfile\r\ndef test():\r\n    def TowerOfHanoi(n, source, destination, auxiliary):\r\n        if n == 1:\r\n            return\r\n        TowerOfHanoi(n - 1, source, auxiliary, destination)\r\n        TowerOfHanoi(n - 1, auxiliary, destination, source)\r\n    TowerOfHanoi(16, \"A\", \"B\", \"C\")\r\npr = cProfile.Profile()\r\n\"\"\"\r\n\r\nfib_setup = \"\"\"\r\nimport cProfile\r\ndef test():\r\n    def fib(n):\r\n        if n \u003c= 1:\r\n            return 1\r\n        return fib(n - 1) + fib(n - 2)\r\n    fib(21)\r\npr = cProfile.Profile()\r\n\"\"\"\r\n\r\ntest_baseline = \"\"\"\r\ntest()\r\n\"\"\"\r\n\r\ntest_profile = \"\"\"\r\npr.enable()\r\ntest()\r\npr.disable()\r\n\"\"\"\r\n\r\nbaseline = timeit.timeit(test_baseline, setup=hanoi_setup, number=100)\r\nprofile = timeit.timeit(test_profile, setup=hanoi_setup, number=100)\r\nprint(f\"Hanoi: {baseline}, {profile}, {profile / baseline}\")\r\n\r\nbaseline = timeit.timeit(test_baseline, setup=fib_setup, number=100)\r\nprofile = timeit.timeit(test_profile, setup=fib_setup, number=100)\r\nprint(f\"fib: {baseline}, {profile}, {profile / baseline}\")\r\n```\r\n\u003c/details\u003e\r\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-103534\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/gaogaotiantian","@type":"Person","name":"gaogaotiantian"},"datePublished":"2023-04-14T06:30:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/103533/cpython/issues/103533"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:3d663641-5074-dc51-eb29-e81c96bbf3ff
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id85EA:2D943D:1249EEC:199F17B:696A328F
html-safe-nonce643e541e567f1dc0a63f695257ddf5de158fcc74b6d29358962c46cdb4646e18
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NUVBOjJEOTQzRDoxMjQ5RUVDOjE5OUYxN0I6Njk2QTMyOEYiLCJ2aXNpdG9yX2lkIjoiNzEwMzA5NDY4OTE2MTE2MzQwNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacc068cd1fdcfb32d52c92b8bb30157cba664bc79ef08cda0d4571510743c2632d
hovercard-subject-tagissue:1667598026
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/103533/issue_layout
twitter:imagehttps://opengraph.githubassets.com/dd1ffa43b8bcb0358b9d27ebd8aee8287fa53491e51c9628b69a1dd22035e505/python/cpython/issues/103533
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/dd1ffa43b8bcb0358b9d27ebd8aee8287fa53491e51c9628b69a1dd22035e505/python/cpython/issues/103533
og:image:altFeature or enhancement Replace the current setprofile mechanism with PEP 669 API for cProfile. Pitch It's faster. Before: Hanoi: 0.342869599997357, 1.4579414000036195, 4.252174587699983 fib: 0.1554...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamegaogaotiantian
hostnamegithub.com
expected-hostnamegithub.com
None321736bfdb3f591415ae895a0459bec204b26a76caf47ba5c980634cfacc4538
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
release7a9163cefd1ea4bd06f8eb7c082f43e4e53f626f
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/103533#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F103533
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F103533
Sign up https://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/103533
Reloadhttps://github.com/python/cpython/issues/103533
Reloadhttps://github.com/python/cpython/issues/103533
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/103533
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/103533
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/103533
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/103533
Use PEP 669 API for cprofilehttps://github.com/python/cpython/issues/103533#top
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/gaogaotiantian
https://github.com/gaogaotiantian
gaogaotiantianhttps://github.com/gaogaotiantian
on Apr 14, 2023https://github.com/python/cpython/issues/103533#issue-1667598026
gh-103533: Use pep669 APIs for cprofile #103534https://github.com/python/cpython/pull/103534
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%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.