René's URL Explorer Experiment


Title: gh-162513: Use `memcmp()` for equality comparisons between contiguous byte `memoryview`s by maurycy · Pull Request #162514 · python/cpython · GitHub

Open Graph Title: gh-162513: Use `memcmp()` for equality comparisons between contiguous byte `memoryview`s by maurycy · Pull Request #162514 · python/cpython

X Title: gh-162513: Use `memcmp()` for equality comparisons between contiguous byte `memoryview`s by maurycy · Pull Request #162514 · python/cpython

Description: Compare a run of bytes in one call to memcmp() in cmp_base(). The fast path applies when both operands have the same native format (B, b or c), both strides are one byte, both suboffset arrays are null, and the run is not empty. This covers a B view compared with bytes or bytearray, and contiguous rows of multidimensional views. Comparisons between different formats still use struct unpacking. Closes #162513 macOS PGO+LTO: Comparison main Patch main / patch 4 KiB, equal 8.43 µs 95.0 ns 88.73× 4 KiB, last byte differs 8.45 µs 95.9 ns 88.13× 4 KiB, first byte differs 15.2 ns 14.9 ns 1.02× 8 bytes, equal 22.2 ns 15.0 ns 1.48× Every other byte, 2,048 elements 4.2 µs 4.17 µs 1.01× Equal 32 × 64 views, contiguous rows, outer stride 128 4.21 µs 164.4 ns 25.58× Open, map and compare two copies of the pip wheel 5.81 ms 314 µs 18.54× Expression Size Equal, main Equal, patch First byte differs, main First byte differs, patch mv == value 0 B 14.8 ns 15.6 ns — — mv == value 1 B 16.6 ns 17.2 ns 16.2 ns 17.3 ns mv == value 4 B 19.9 ns 16.7 ns 16.6 ns 17.0 ns mv == value 16 B 35.8 ns 16.6 ns 16.8 ns 17.0 ns mv == value 100 B 207.9 ns 18.0 ns 17.0 ns 16.7 ns packet[:4] == magic 4 B 42.8 ns 37.6 ns 38.9 ns 38.7 ns packet[:16] == magic 16 B 57.6 ns 38.9 ns 38.8 ns 38.6 ns Comparison main Patch main / patch Unsigned byte view vs. bytearray, 100 bytes, equal 205.7 ns 18.5 ns 11.15× Signed byte view (b) vs. bytes, 4 zero bytes, equal 744.9 ns 758.2 ns 0.98× Character view (c) vs. bytes, 4 zero bytes, unequal 609.5 ns 615.6 ns 0.99× bench import ensurepip import mmap import tempfile from pathlib import Path import pyperf def compare_files(path1, path2): with path1.open("rb") as f1, path2.open("rb") as f2: with ( mmap.mmap(f1.fileno(), 0, access=mmap.ACCESS_READ) as m1, mmap.mmap(f2.fileno(), 0, access=mmap.ACCESS_READ) as m2, memoryview(m1) as v1, memoryview(m2) as v2, ): return v1 == v2 left = memoryview(bytearray(4096)) right = memoryview(bytearray(4096)) first_diff = memoryview(b"x" + bytes(4095)) last_diff = memoryview(bytes(4095) + b"x") short_left, short_right = left[:8], right[:8] strided_left, strided_right = left[::2], right[::2] runner = pyperf.Runner() for stmt in ( "left == right", "left == last_diff", "left == first_diff", "short_left == short_right", "strided_left == strided_right", ): runner.timeit(stmt, stmt, globals=globals()) packet = memoryview(bytes(128)) for size in (0, 1, 4, 16, 100): view = packet[:size] equal = bytes(size) runner.timeit(f"mv == bytes/{size}/equal", "view == equal", globals=globals()) if size: miss = b"x" + bytes(size - 1) runner.timeit(f"mv == bytes/{size}/first differs", "view == miss", globals=globals()) if size in (4, 16): for outcome, magic in (("equal", equal), ("first differs", miss)): stmt = f"packet[:{size}] == magic" runner.timeit(f"slice == bytes/{size}/{outcome}", stmt, globals=globals()) mutable = bytearray(100) view = packet[:100] signed = packet[:4].cast("b") chars = packet[:4].cast("c") raw = bytes(4) rows_left = left.cast("B", (64, 64))[::2] rows_right = right.cast("B", (64, 64))[::2] for stmt in ("view == mutable", "signed == raw", "chars == raw", "rows_left == rows_right"): runner.timeit(stmt, stmt, globals=globals()) wheel = next(Path(ensurepip.__file__).with_name("_bundled").glob("pip-*.whl")) with tempfile.TemporaryDirectory() as tmp: copy = Path(tmp) / wheel.name copy.write_bytes(wheel.read_bytes()) assert compare_files(wheel, copy) runner.bench_func("open, mmap and compare two pip wheels", compare_files, wheel, copy) Issue: gh-162513

Open Graph Description: Compare a run of bytes in one call to memcmp() in cmp_base(). The fast path applies when both operands have the same native format (B, b or c), both strides are one byte, both suboffset arrays are ...

X Description: Compare a run of bytes in one call to memcmp() in cmp_base(). The fast path applies when both operands have the same native format (B, b or c), both strides are one byte, both suboffset arrays are ...

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

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.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:39ae1ab7-f9d7-346a-36e4-8fbbb9228261
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id9FDC:39ABD:DFAB54:12FBC74:6B0652DB
html-safe-nonce0001b9d1bf46d65f29126d22a6240da7a028952db8b079283515c75517d6c9af
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkRDOjM5QUJEOkRGQUI1NDoxMkZCQzc0OjZCMDY1MkRCIiwidmlzaXRvcl9pZCI6IjYzMTYwMDEwOTEzNTIxNTQ4NDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac546aba0d4b51985976ec01e2a9e697c15bf2850016bc98b3bcae3b64fd26660d
hovercard-subject-tagpull_request:5462987376
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/162514/files
twitter:imagehttps://avatars.githubusercontent.com/u/5383?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/5383?s=400&v=4
og:image:altCompare a run of bytes in one call to memcmp() in cmp_base(). The fast path applies when both operands have the same native format (B, b or c), both strides are one byte, both suboffset arrays are ...
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/162514/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F162514%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%2F162514%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/162514/files
Reloadhttps://github.com/python/cpython/pull/162514/files
Reloadhttps://github.com/python/cpython/pull/162514/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
maurycyhttps://github.com/maurycy
python:mainhttps://github.com/python/cpython/tree/main
maurycy:memoryview-byte-equalityhttps://github.com/maurycy/cpython/tree/memoryview-byte-equality
Conversation 3 https://github.com/python/cpython/pull/162514
Commits 6 https://github.com/python/cpython/pull/162514/commits
Checks 53 https://github.com/python/cpython/pull/162514/checks
Files changed https://github.com/python/cpython/pull/162514/files
Please reload this pagehttps://github.com/python/cpython/pull/162514/files
gh-162513: Use memcmp() for equality comparisons between contiguous byte memoryviews https://github.com/python/cpython/pull/162514/files#top
Show all changes 6 commits https://github.com/python/cpython/pull/162514/files
b42914c memcmp maurycy Nov 23, 2026 https://github.com/python/cpython/pull/162514/commits/b42914cdad71a067e2572df430b8435d9ee2d38f
da0b5a9 test maurycy Nov 23, 2026 https://github.com/python/cpython/pull/162514/commits/da0b5a9306cfa46c7621c284ebc4f717e666e52e
bb5e152 news maurycy Nov 23, 2026 https://github.com/python/cpython/pull/162514/commits/bb5e152fd272dc109aa5e24d129206c7845e3ce1
1ac2545 claim credit maurycy Nov 23, 2026 https://github.com/python/cpython/pull/162514/commits/1ac254522dfcca989f17dfce005c9bc95e603a6f
5b2b544 pep 7 maurycy Nov 23, 2026 https://github.com/python/cpython/pull/162514/commits/5b2b544beb4e0c90ef1423310a243e2f28181d8e
affb52d worth testing maurycy Nov 23, 2026 https://github.com/python/cpython/pull/162514/commits/affb52d0380a6c04898c1889070a803385b7836f
Clear filters https://github.com/python/cpython/pull/162514/files
Please reload this pagehttps://github.com/python/cpython/pull/162514/files
Please reload this pagehttps://github.com/python/cpython/pull/162514/files
test_memoryview.py https://github.com/python/cpython/pull/162514/files#diff-d41c6bb40a1e03fea5a20d15c4077413e0ddde65651147922b625b03a66a2f16
2026-11-24-00-25-22.gh-issue-162513.6-uUKS.rst https://github.com/python/cpython/pull/162514/files#diff-c43a79acd692ba1d8214b76b231f7b130f1e8e2c26be3e35fc1eec4cc158a652
memoryobject.c https://github.com/python/cpython/pull/162514/files#diff-7d1cb11da20dc3738b65b0f7381bf02df53132562a9749ba8a22d67a0f05f106
Lib/test/test_memoryview.pyhttps://github.com/python/cpython/pull/162514/files#diff-d41c6bb40a1e03fea5a20d15c4077413e0ddde65651147922b625b03a66a2f16
View file https://github.com/python/cpython/blob/affb52d0380a6c04898c1889070a803385b7836f/Lib/test/test_memoryview.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/162514/{{ revealButtonHref }}
https://github.com/python/cpython/pull/162514/files#diff-d41c6bb40a1e03fea5a20d15c4077413e0ddde65651147922b625b03a66a2f16
https://github.com/python/cpython/pull/162514/files#diff-d41c6bb40a1e03fea5a20d15c4077413e0ddde65651147922b625b03a66a2f16
Misc/NEWS.d/next/Core_and_Builtins/2026-11-24-00-25-22.gh-issue-162513.6-uUKS.rsthttps://github.com/python/cpython/pull/162514/files#diff-c43a79acd692ba1d8214b76b231f7b130f1e8e2c26be3e35fc1eec4cc158a652
View file https://github.com/python/cpython/blob/affb52d0380a6c04898c1889070a803385b7836f/Misc/NEWS.d/next/Core_and_Builtins/2026-11-24-00-25-22.gh-issue-162513.6-uUKS.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/162514/{{ revealButtonHref }}
Objects/memoryobject.chttps://github.com/python/cpython/pull/162514/files#diff-7d1cb11da20dc3738b65b0f7381bf02df53132562a9749ba8a22d67a0f05f106
View file https://github.com/python/cpython/blob/affb52d0380a6c04898c1889070a803385b7836f/Objects/memoryobject.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/162514/{{ revealButtonHref }}
https://github.com/python/cpython/pull/162514/files#diff-7d1cb11da20dc3738b65b0f7381bf02df53132562a9749ba8a22d67a0f05f106
eendebakpthttps://github.com/eendebakpt
Nov 24, 2026https://github.com/python/cpython/pull/162514/files#r4673695974
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
main...eendebakpt:memoryview-cmp-typed-loopshttps://github.com/python/cpython/compare/main...eendebakpt:memoryview-cmp-typed-loops
Please reload this pagehttps://github.com/python/cpython/pull/162514/files
https://github.com/python/cpython/pull/162514/files#diff-7d1cb11da20dc3738b65b0f7381bf02df53132562a9749ba8a22d67a0f05f106
Please reload this pagehttps://github.com/python/cpython/pull/162514/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.