René's URL Explorer Experiment


Title: gh-146558: optimize dict access with objects with known hash by kumaraditya303 · Pull Request #146559 · python/cpython · GitHub

Open Graph Title: gh-146558: optimize dict access with objects with known hash by kumaraditya303 · Pull Request #146559 · python/cpython

X Title: gh-146558: optimize dict access with objects with known hash by kumaraditya303 · Pull Request #146559 · python/cpython

Description: I asked Claude to create a benchmark for this, it created the following script which shows a real significant speedup. Benchmark No JIT JIT Speedup dict_get[str] 55.7M/s 70.1M/s +26% dict_get[int] 55.5M/s 75.4M/s +36% dict_get[float] 50.9M/s 74.7M/s +47% dict_get[complex] 44.9M/s 74.9M/s +67% dict_store[str] 74.9M/s 85.7M/s +14% dict_store[int] 76.0M/s 94.1M/s +24% dict_store[float] 66.6M/s 97.0M/s +46% dict_store[complex] 55.9M/s 98.0M/s +75% dict_get[multi] 23.4M/s 35.1M/s +50% dict_get[obj] 52.9M/s 68.8M/s +30% dict_store[obj] 75.4M/s 92.5M/s +23% Details """Benchmark dict get/store with constant keys to measure _BINARY_OP_SUBSCR_DICT_KNOWN_HASH and _STORE_SUBSCR_DICT_KNOWN_HASH speedup. Usage: PYTHON_JIT=0 ./python.exe bench_dict_known_hash.py PYTHON_JIT=1 ./python.exe bench_dict_known_hash.py """ import time import os import sys N = 50_000_000 def bench_get_str(n): d = {'a': 1, 'b': 2, 'c': 3} x = 0 for _ in range(n): x += d['a'] return x def bench_get_int(n): d = {1: 10, 2: 20, 3: 30} x = 0 for _ in range(n): x += d[1] return x def bench_store_str(n): d = {} for _ in range(n): d['a'] = 1 return d def bench_store_int(n): d = {} for _ in range(n): d[1] = 1 return d def bench_get_float(n): d = {1.5: 1, 2.5: 2, 3.5: 3} x = 0 for _ in range(n): x += d[1.5] return x def bench_store_float(n): d = {} for _ in range(n): d[1.5] = 1 return d def bench_get_complex(n): d = {1+2j: 1, 3+4j: 2} x = 0 for _ in range(n): x += d[1+2j] return x def bench_store_complex(n): d = {} for _ in range(n): d[1+2j] = 1 return d def bench_get_multi(n): d = {'a': 1, 1: 2, b'x': 3, (1, 2): 4} x = 0 for _ in range(n): x += d['a'] + d[1] + d[b'x'] + d[(1, 2)] return x class _Key: pass _KEY = _Key() def bench_get_obj(n): d = {_KEY: 1} x = 0 for _ in range(n): x += d[_KEY] return x def bench_store_obj(n): d = {} for _ in range(n): d[_KEY] = 1 return d def run_avg(name, func, n, runs=3): func(1000) # warmup times = [] for _ in range(runs): t0 = time.perf_counter() func(n) times.append(time.perf_counter() - t0) avg = sum(times) / len(times) rate = n / avg / 1e6 print(f" {name:25s} {avg:.3f}s ({rate:.1f}M iter/s)") return avg if __name__ == "__main__": jit = "JIT" if os.environ.get("PYTHON_JIT", "1") == "1" else "no JIT" print(f"Python {sys.version.split()[0]} ({jit}), avg of 3 runs\n") run_avg("dict_get[str]", bench_get_str, N) run_avg("dict_get[int]", bench_get_int, N) run_avg("dict_get[float]", bench_get_float, N) run_avg("dict_get[complex]", bench_get_complex, N) run_avg("dict_store[str]", bench_store_str, N) run_avg("dict_store[int]", bench_store_int, N) run_avg("dict_store[float]", bench_store_float, N) run_avg("dict_store[complex]",bench_store_complex,N) run_avg("dict_get[multi]", bench_get_multi, N // 4) run_avg("dict_get[obj]", bench_get_obj, N) run_avg("dict_store[obj]", bench_store_obj, N) Issue: gh-146558

Open Graph Description: I asked Claude to create a benchmark for this, it created the following script which shows a real significant speedup. Benchmark No JIT JIT Speedup dict_get[str] 55.7M/s 70.1M/s +26% dict_...

X Description: I asked Claude to create a benchmark for this, it created the following script which shows a real significant speedup. Benchmark No JIT JIT Speedup dict_get[str] 55.7M/s 70.1M/s +26% dict_...

Opengraph URL: https://github.com/python/cpython/pull/146559

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:f1e326a6-6da2-2bb2-b13f-c73f6b1183b7
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idD094:2BE11D:106CE17:164E12D:6A5228E0
html-safe-nonce604a1a772551c054c2e874179c332d3842f8a1c8585832b013d48793b7ac3cde
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDk0OjJCRTExRDoxMDZDRTE3OjE2NEUxMkQ6NkE1MjI4RTAiLCJ2aXNpdG9yX2lkIjoiNDAwOTQ5ODMxOTMxNTQxMzIxNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac6b337026bbad655ede4da748389393ffecfd9c933c3d6c6c547667a310d339a5
hovercard-subject-tagpull_request:3460355401
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/146559/files
twitter:imagehttps://avatars.githubusercontent.com/u/59607654?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/59607654?s=400&v=4
og:image:altI asked Claude to create a benchmark for this, it created the following script which shows a real significant speedup. Benchmark No JIT JIT Speedup dict_get[str] 55.7M/s 70.1M/s +26% dict_...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
diff-viewunified
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 full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7aed05249554b889eb33d002851a973eebcc7e91
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/146559/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F146559%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
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
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
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/enterprise/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%2Fpull%2F146559%2Ffiles
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%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/146559/files
Reloadhttps://github.com/python/cpython/pull/146559/files
Reloadhttps://github.com/python/cpython/pull/146559/files
Please reload this pagehttps://github.com/python/cpython/pull/146559/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/146559/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k 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.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
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 and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
kumaraditya303https://github.com/kumaraditya303
python:mainhttps://github.com/python/cpython/tree/main
kumaraditya303:jit-hashhttps://github.com/kumaraditya303/cpython/tree/jit-hash
Conversation 1 https://github.com/python/cpython/pull/146559
Commits 8 https://github.com/python/cpython/pull/146559/commits
Checks 78 https://github.com/python/cpython/pull/146559/checks
Files changed 10 https://github.com/python/cpython/pull/146559/files
gh-146558: optimize dict access with objects with known hash https://github.com/python/cpython/pull/146559/files#top
Show all changes 8 commits https://github.com/python/cpython/pull/146559/files
b441e1b optimize dict access with objects with safe hash kumaraditya303 Mar 28, 2026 https://github.com/python/cpython/pull/146559/commits/b441e1baab9d1533f809868634e8be5ddf910130
a5b4476 fix build on windows kumaraditya303 Mar 28, 2026 https://github.com/python/cpython/pull/146559/commits/a5b447611658ae1d4dc2d8b583fb09c005a45491
3263498 remove benchmark kumaraditya303 Mar 28, 2026 https://github.com/python/cpython/pull/146559/commits/3263498d05194b97e69faf54c26168ecc28d73fe
3af5968 improve comments kumaraditya303 Mar 28, 2026 https://github.com/python/cpython/pull/146559/commits/3af5968873a764f6c2db788dbe3c9fba91f5685b
7707961 run regen kumaraditya303 Mar 28, 2026 https://github.com/python/cpython/pull/146559/commits/7707961c9bd8f40298c04501685fbc5bdcf5ef72
2d1a169 fix test warning kumaraditya303 Mar 28, 2026 https://github.com/python/cpython/pull/146559/commits/2d1a169afd0e921c99a5e1a2d6a6fa8e5badaf5d
ea4ae79 optimize floats and complex as well kumaraditya303 Mar 28, 2026 https://github.com/python/cpython/pull/146559/commits/ea4ae79c95190a8957fcb71488d50f986beb8392
7a4d046 refactor common code to optimize_dict_known_hash kumaraditya303 Mar 30, 2026 https://github.com/python/cpython/pull/146559/commits/7a4d046116c1c1f76e68afbecf8e28dc1c98d437
Clear filters https://github.com/python/cpython/pull/146559/files
Please reload this pagehttps://github.com/python/cpython/pull/146559/files
Please reload this pagehttps://github.com/python/cpython/pull/146559/files
pycore_dict.h https://github.com/python/cpython/pull/146559/files#diff-47692c69ef97b2d7cf05ad8e0fa2024b575af96abf9bbc5486f71156ab67ede4
pycore_uop_ids.h https://github.com/python/cpython/pull/146559/files#diff-2a420e4d0d58009249c0f73f7c822167b053bd51cb213b20179bd2aebfc66ff9
pycore_uop_metadata.h https://github.com/python/cpython/pull/146559/files#diff-55e65a72fa31e9b746e03076d2c74b716c0c1171663f36960b2339fcbfae9bab
test_opt.py https://github.com/python/cpython/pull/146559/files#diff-67b5bd915e37f77df79907865982648172c27d3b96fbb072b30a73c6a2735439
dictobject.c https://github.com/python/cpython/pull/146559/files#diff-b08a47ddc5bc20b2e99ac2e5aa199ca24a56b994e7bc64e918513356088c20ae
bytecodes.c https://github.com/python/cpython/pull/146559/files#diff-729a985b0cb8b431cb291f1edb561bbbfea22e3f8c262451cd83328a0936a342
executor_cases.c.h https://github.com/python/cpython/pull/146559/files#diff-a1c3430c42a66c16e6d2e154491a6da993b187b27c628545a12a02c7b2a06b81
optimizer_analysis.c https://github.com/python/cpython/pull/146559/files#diff-eac5ab7e741b8b825a24d31a5bf844e86086431fb698cfcabe1277b68c375ca2
optimizer_bytecodes.c https://github.com/python/cpython/pull/146559/files#diff-e5bd2b14b0b10f0f47786e26306d689ed1361c3dc3b11dcc3ea52b8a2422ff64
optimizer_cases.c.h https://github.com/python/cpython/pull/146559/files#diff-ed4567b3e67709ec57bf4df91ef058cfcbe00d7da11cd2a75e38241fa1ca99d2
Include/internal/pycore_dict.hhttps://github.com/python/cpython/pull/146559/files#diff-47692c69ef97b2d7cf05ad8e0fa2024b575af96abf9bbc5486f71156ab67ede4
View file https://github.com/kumaraditya303/cpython/blob/7a4d046116c1c1f76e68afbecf8e28dc1c98d437/Include/internal/pycore_dict.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/146559/{{ revealButtonHref }}
https://github.com/python/cpython/pull/146559/files#diff-47692c69ef97b2d7cf05ad8e0fa2024b575af96abf9bbc5486f71156ab67ede4
https://github.com/python/cpython/pull/146559/files#diff-47692c69ef97b2d7cf05ad8e0fa2024b575af96abf9bbc5486f71156ab67ede4
Please reload this pagehttps://github.com/python/cpython/pull/146559/files
Please reload this pagehttps://github.com/python/cpython/pull/146559/files
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.