René's URL Explorer Experiment


Title: gh-159716: Faster integer array and memoryview searching by cmaloney · Pull Request #160541 · python/cpython · GitHub

Open Graph Title: gh-159716: Faster integer array and memoryview searching by cmaloney · Pull Request #160541 · python/cpython

X Title: gh-159716: Faster integer array and memoryview searching by cmaloney · Pull Request #160541 · python/cpython

Description: Speed up in, .count(), .index() and array.array.remove() for array.array and memoryview objects with integer formats by comparing the bytes of the items instead of creating an object for each item. The search is implemented using the buffer protocol to get a contiguous buffer, with a fallback to iteration and rich comparison. The buffer is held for the whole search, so a comparison which resizes the array or releases the memoryview now raises BufferError rather than allowing the resize while iterating. Add a sq_contains slot to memoryview so in uses the faster search when possible. The buffer protocol adds 7 ns of overhead per call on my M3 MacBook relative to passing native pointers. The overhead makes searches which stop at the first item or have fewer than two items slower. Longer cases get substantially faster; full results are below. in, memoryview.index() and .count() with the 'w' format (Py_UCS4) now work, because searching shares array's support for 'w'; they used to raise NotImplementedError. Other memoryview operations still don't support 'w'. memoryview.index() with an unsupported format now raises NotImplementedError even when there are no items to search, as .count() and in already did; it used to raise ValueError. pyperf, release build (-O3) without PGO or LTO, macOS arm64: Benchmark main patch array i[8] in (first) 9.41 ns 16.6 ns: 1.76x slower array i[8] in (last) 57.3 ns 19.0 ns: 3.01x faster array i[8] index (first) 13.9 ns 21.5 ns: 1.55x slower array i[8] count 69.9 ns 20.7 ns: 3.37x faster array d[8] index (first) 20.4 ns 26.3 ns: 1.29x slower array d[8] count 94.4 ns 96.8 ns: 1.03x slower memoryview i[8] index (first) 14.4 ns 22.6 ns: 1.57x slower memoryview i[8] count 88.1 ns 22.4 ns: 3.94x faster memoryview d[8] count 125 ns 96.7 ns: 1.29x faster array i[1k] count 10.5 us 136 ns: 77.22x faster memoryview i[1k:2] count 10.0 us 8.38 us: 1.19x faster memoryview d[1k] count 10.8 us 10.1 us: 1.07x faster array B[100k] in (miss) 616 us 1.77 us: 348.22x faster array i[100k] index (last) 1.16 ms 9.38 us: 123.36x faster array q[100k] count 1.30 ms 7.46 us: 173.79x faster memoryview B[100k] count 805 us 13.0 us: 61.90x faster memoryview i[100k] index (last) 1.21 ms 9.26 us: 131.19x faster Geometric mean (ref) 5.28x faster Benchmark hidden because not significant (2): array d[1k] count, array w[1k] count Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Issue: gh-159716

Open Graph Description: Speed up in, .count(), .index() and array.array.remove() for array.array and memoryview objects with integer formats by comparing the bytes of the items instead of creating an object for each item....

X Description: Speed up in, .count(), .index() and array.array.remove() for array.array and memoryview objects with integer formats by comparing the bytes of the items instead of creating an object for each item....

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

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.113.3

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/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:3c842460-0a4f-398f-9ec9-c0c01869fd66
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA918:27D516:10E783B:166F9FC:6B065184
html-safe-nonce19871c1b10a3c4c584a34d0ae6083dcd8ab361e56f3bf74031ffd5e68e2f4aaf
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOTE4OjI3RDUxNjoxMEU3ODNCOjE2NkY5RkM6NkIwNjUxODQiLCJ2aXNpdG9yX2lkIjoiMjg3Njk5ODUyNTIxOTM5MzkyNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaccf1ca831c8f7d3a791b1a8f271481fc5cfba4295c8b5066d942a6a14a09d2f2d
hovercard-subject-tagpull_request:4990530306
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/160541/files
twitter:imagehttps://avatars.githubusercontent.com/u/751088?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/751088?s=400&v=4
og:image:altSpeed up in, .count(), .index() and array.array.remove() for array.array and memoryview objects with integer formats by comparing the bytes of the items instead of creating an object for each item....
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e
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
releasef1f9a08f7c769a37f1dfc18ad43d463c222a7eea
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/160541/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F160541%2Ffiles
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%2Fpull%2F160541%2Ffiles
Sign uphttps://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/160541/files
Reloadhttps://github.com/python/cpython/pull/160541/files
Reloadhttps://github.com/python/cpython/pull/160541/files
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
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
cmaloneyhttps://github.com/cmaloney
python:mainhttps://github.com/python/cpython/tree/main
cmaloney:mv_speeduphttps://github.com/cmaloney/cpython/tree/mv_speedup
Conversation 0 https://github.com/python/cpython/pull/160541
Commits 3 https://github.com/python/cpython/pull/160541/commits
Checks 52 https://github.com/python/cpython/pull/160541/checks
Files changed https://github.com/python/cpython/pull/160541/files
Please reload this pagehttps://github.com/python/cpython/pull/160541/files
gh-159716: Faster integer array and memoryview searching https://github.com/python/cpython/pull/160541/files#top
Show all changes 3 commits https://github.com/python/cpython/pull/160541/files
59d1c5b gh-159716: Faster integer array and memoryview searching cmaloney Oct 21, 2026 https://github.com/python/cpython/pull/160541/commits/59d1c5b2f2a3eda04ceec789b2aee89863fdd5e2
c8be70d review fixes cmaloney Oct 23, 2026 https://github.com/python/cpython/pull/160541/commits/c8be70d35b71ab5b550dad71c59d50f358a0ebfb
451de14 quiet bytes warning in test cmaloney Oct 24, 2026 https://github.com/python/cpython/pull/160541/commits/451de14e80c4e2db6379957b0412c9fab091a636
Clear filters https://github.com/python/cpython/pull/160541/files
Please reload this pagehttps://github.com/python/cpython/pull/160541/files
Please reload this pagehttps://github.com/python/cpython/pull/160541/files
pycore_pybuffer.h https://github.com/python/cpython/pull/160541/files#diff-04aa98a653366dc974e0c6b8fc059cdeeb22f49aea528667160680da533a747b
seq_tests.py https://github.com/python/cpython/pull/160541/files#diff-f843c66d70ebff49c5ddef83b14ad85d28d10e830dd75c47e93e422972af2530
test_array.py https://github.com/python/cpython/pull/160541/files#diff-9171e2213953c56e609d6fae2f15892982341fd9f076fe69c4a73c3e52d7dfb9
test_buffer.py https://github.com/python/cpython/pull/160541/files#diff-ccd9f4a5ebfeaa46497d8bb31b8cf32a1f73a7e127474770a659124beaa815ff
test_memoryview.py https://github.com/python/cpython/pull/160541/files#diff-d41c6bb40a1e03fea5a20d15c4077413e0ddde65651147922b625b03a66a2f16
2026-10-21-14-04-17.gh-issue-159716.mGLRXB.rst https://github.com/python/cpython/pull/160541/files#diff-88035f7de9eb454dd76cf5cd071da17988795468c90db1d832042475992ae1b5
2026-10-23-14-54-46.gh-issue-159716.ZKNJS2.rst https://github.com/python/cpython/pull/160541/files#diff-184aad8b8ffd839fd1128a1153099fb28c457622f7579072cc0e52ce315a467f
arraymodule.c https://github.com/python/cpython/pull/160541/files#diff-a64ccdf7f6d9fe7fbe417fe2d24c7803c152b75640bdc5a6539754aa71bc6a51
memoryobject.c https://github.com/python/cpython/pull/160541/files#diff-7d1cb11da20dc3738b65b0f7381bf02df53132562a9749ba8a22d67a0f05f106
Include/internal/pycore_pybuffer.hhttps://github.com/python/cpython/pull/160541/files#diff-04aa98a653366dc974e0c6b8fc059cdeeb22f49aea528667160680da533a747b
View file https://github.com/python/cpython/blob/451de14e80c4e2db6379957b0412c9fab091a636/Include/internal/pycore_pybuffer.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/160541/{{ revealButtonHref }}
https://github.com/python/cpython/pull/160541/files#diff-04aa98a653366dc974e0c6b8fc059cdeeb22f49aea528667160680da533a747b
https://github.com/python/cpython/pull/160541/files#diff-04aa98a653366dc974e0c6b8fc059cdeeb22f49aea528667160680da533a747b
Lib/test/seq_tests.pyhttps://github.com/python/cpython/pull/160541/files#diff-f843c66d70ebff49c5ddef83b14ad85d28d10e830dd75c47e93e422972af2530
View file https://github.com/python/cpython/blob/451de14e80c4e2db6379957b0412c9fab091a636/Lib/test/seq_tests.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/160541/{{ revealButtonHref }}
https://github.com/python/cpython/pull/160541/files#diff-f843c66d70ebff49c5ddef83b14ad85d28d10e830dd75c47e93e422972af2530
https://github.com/python/cpython/pull/160541/files#diff-f843c66d70ebff49c5ddef83b14ad85d28d10e830dd75c47e93e422972af2530
https://github.com/python/cpython/pull/160541/files#diff-f843c66d70ebff49c5ddef83b14ad85d28d10e830dd75c47e93e422972af2530
Lib/test/test_array.pyhttps://github.com/python/cpython/pull/160541/files#diff-9171e2213953c56e609d6fae2f15892982341fd9f076fe69c4a73c3e52d7dfb9
View file https://github.com/python/cpython/blob/451de14e80c4e2db6379957b0412c9fab091a636/Lib/test/test_array.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/160541/{{ revealButtonHref }}
https://github.com/python/cpython/pull/160541/files#diff-9171e2213953c56e609d6fae2f15892982341fd9f076fe69c4a73c3e52d7dfb9
https://github.com/python/cpython/pull/160541/files#diff-9171e2213953c56e609d6fae2f15892982341fd9f076fe69c4a73c3e52d7dfb9
https://github.com/python/cpython/pull/160541/files#diff-9171e2213953c56e609d6fae2f15892982341fd9f076fe69c4a73c3e52d7dfb9
https://github.com/python/cpython/pull/160541/files#diff-9171e2213953c56e609d6fae2f15892982341fd9f076fe69c4a73c3e52d7dfb9
https://github.com/python/cpython/pull/160541/files#diff-9171e2213953c56e609d6fae2f15892982341fd9f076fe69c4a73c3e52d7dfb9
https://github.com/python/cpython/pull/160541/files#diff-9171e2213953c56e609d6fae2f15892982341fd9f076fe69c4a73c3e52d7dfb9
Lib/test/test_buffer.pyhttps://github.com/python/cpython/pull/160541/files#diff-ccd9f4a5ebfeaa46497d8bb31b8cf32a1f73a7e127474770a659124beaa815ff
View file https://github.com/python/cpython/blob/451de14e80c4e2db6379957b0412c9fab091a636/Lib/test/test_buffer.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/160541/{{ revealButtonHref }}
https://github.com/python/cpython/pull/160541/files#diff-ccd9f4a5ebfeaa46497d8bb31b8cf32a1f73a7e127474770a659124beaa815ff
https://github.com/python/cpython/pull/160541/files#diff-ccd9f4a5ebfeaa46497d8bb31b8cf32a1f73a7e127474770a659124beaa815ff
https://github.com/python/cpython/pull/160541/files#diff-ccd9f4a5ebfeaa46497d8bb31b8cf32a1f73a7e127474770a659124beaa815ff
https://github.com/python/cpython/pull/160541/files#diff-ccd9f4a5ebfeaa46497d8bb31b8cf32a1f73a7e127474770a659124beaa815ff
Lib/test/test_memoryview.pyhttps://github.com/python/cpython/pull/160541/files#diff-d41c6bb40a1e03fea5a20d15c4077413e0ddde65651147922b625b03a66a2f16
View file https://github.com/python/cpython/blob/451de14e80c4e2db6379957b0412c9fab091a636/Lib/test/test_memoryview.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/160541/{{ revealButtonHref }}
https://github.com/python/cpython/pull/160541/files#diff-d41c6bb40a1e03fea5a20d15c4077413e0ddde65651147922b625b03a66a2f16
https://github.com/python/cpython/pull/160541/files#diff-d41c6bb40a1e03fea5a20d15c4077413e0ddde65651147922b625b03a66a2f16
https://github.com/python/cpython/pull/160541/files#diff-d41c6bb40a1e03fea5a20d15c4077413e0ddde65651147922b625b03a66a2f16
https://github.com/python/cpython/pull/160541/files#diff-d41c6bb40a1e03fea5a20d15c4077413e0ddde65651147922b625b03a66a2f16
Misc/NEWS.d/next/Core_and_Builtins/2026-10-21-14-04-17.gh-issue-159716.mGLRXB.rsthttps://github.com/python/cpython/pull/160541/files#diff-88035f7de9eb454dd76cf5cd071da17988795468c90db1d832042475992ae1b5
View file https://github.com/python/cpython/blob/451de14e80c4e2db6379957b0412c9fab091a636/Misc/NEWS.d/next/Core_and_Builtins/2026-10-21-14-04-17.gh-issue-159716.mGLRXB.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/160541/{{ revealButtonHref }}
Misc/NEWS.d/next/Library/2026-10-23-14-54-46.gh-issue-159716.ZKNJS2.rsthttps://github.com/python/cpython/pull/160541/files#diff-184aad8b8ffd839fd1128a1153099fb28c457622f7579072cc0e52ce315a467f
View file https://github.com/python/cpython/blob/451de14e80c4e2db6379957b0412c9fab091a636/Misc/NEWS.d/next/Library/2026-10-23-14-54-46.gh-issue-159716.ZKNJS2.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/160541/{{ revealButtonHref }}
Please reload this pagehttps://github.com/python/cpython/pull/160541/files
Please reload this pagehttps://github.com/python/cpython/pull/160541/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

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlno-cache

Viewport: width=device-width


URLs of crawlers that visited me.