René's URL Explorer Experiment


Title: bpo-33234 Improve list() pre-sizing for inputs with known lengths (no __length_hint__) by pablogsal · Pull Request #9846 · python/cpython · GitHub

Open Graph Title: bpo-33234 Improve list() pre-sizing for inputs with known lengths (no __length_hint__) by pablogsal · Pull Request #9846 · python/cpython

X Title: bpo-33234 Improve list() pre-sizing for inputs with known lengths (no __length_hint__) by pablogsal · Pull Request #9846 · python/cpython

Description: This is a version of #6493 that only preallocates the list when __len__ is available to reduce memory overallocation and possible performance hit on big iterables. This are the L1 and L2 cache misses and related information: THIS PR ❯ perf stat -r 200 -B -e cache-references,cache-misses,cycles,instructions,branches,faults,migrations ./python -c " for _ in range(1000): list([0]*10000) " Performance counter stats for './python -c for _ in range(1000): list([0]*10000) ' (200 runs): 1,151,365 cache-references:u ( +- 0.47% ) 5,686 cache-misses:u # 0.494 % of all cache refs ( +- 8.06% ) 370,237,437 cycles:u ( +- 0.05% ) 542,049,270 instructions:u # 1.46 insn per cycle ( +- 0.00% ) 134,146,925 branches:u ( +- 0.00% ) 8,031 faults:u ( +- 0.00% ) 0 migrations:u 0.122170 +- 0.000307 seconds time elapsed ( +- 0.25% ) MASTER ❯ perf stat -r 200 -B -e cache-references,cache-misses,cycles,instructions,branches,faults,migrations ./python -c "for _ in range(1000): list([0]*10000) " Performance counter stats for './python -c for _ in range(1000): list([0]*10000) ' (200 runs): 1,275,440 cache-references:u ( +- 0.61% ) 21,895 cache-misses:u # 1.717 % of all cache refs ( +- 4.69% ) 392,293,096 cycles:u ( +- 0.22% ) 543,254,939 instructions:u # 1.38 insn per cycle ( +- 0.00% ) 134,549,173 branches:u ( +- 0.00% ) 10,039 faults:u ( +- 0.00% ) 0 migrations:u 0.133171 +- 0.000463 seconds time elapsed ( +- 0.35% ) https://bugs.python.org/issue33234

Open Graph Description: This is a version of #6493 that only preallocates the list when __len__ is available to reduce memory overallocation and possible performance hit on big iterables. This are the L1 and L2 cache miss...

X Description: This is a version of #6493 that only preallocates the list when __len__ is available to reduce memory overallocation and possible performance hit on big iterables. This are the L1 and L2 cache miss...

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

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files/:range(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:a7e6c3f0-6b0b-ddbd-e6ae-20e7c03ce082
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA076:1B8326:7931530:A4B1DDF:699611A1
html-safe-nonced55633c033c56de2297232e6d8294818a870060c0e8d414408ff1c299bb2fba5
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDc2OjFCODMyNjo3OTMxNTMwOkE0QjFEREY6Njk5NjExQTEiLCJ2aXNpdG9yX2lkIjoiODU4NDE2NTc4MjY3ODAxNjQxNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac02039fe5d6631575b43d0d592b330e1c77a5f6738bae3c6b4ff8460bd3d51f32
hovercard-subject-tagpull_request:222662280
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/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
twitter:imagehttps://avatars.githubusercontent.com/u/11718525?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/11718525?s=400&v=4
og:image:altThis is a version of #6493 that only preallocates the list when __len__ is available to reduce memory overallocation and possible performance hit on big iterables. This are the L1 and L2 cache miss...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None7490a2fd98baca866acf503b81aa249491b42e5b4bab7f7a2801be81175c8845
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
release48a904441630875f5985de713035046dc65cc94c
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F9846%2Ffiles%2F39a87576b5a3075ec5e0a512065901b436bf8e54
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%2Fpull%2F9846%2Ffiles%2F39a87576b5a3075ec5e0a512065901b436bf8e54
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/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
Reloadhttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
Reloadhttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 34.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.6k 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 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 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
pablogsalhttps://github.com/pablogsal
python:masterhttps://github.com/python/cpython/tree/master
pablogsal:bpo33234-2https://github.com/pablogsal/cpython/tree/bpo33234-2
Conversation 39 https://github.com/python/cpython/pull/9846
Commits 10 https://github.com/python/cpython/pull/9846/commits
Checks 0 https://github.com/python/cpython/pull/9846/checks
Files changed https://github.com/python/cpython/pull/9846/files
Please reload this pagehttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
bpo-33234 Improve list() pre-sizing for inputs with known lengths (no __length_hint__) https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#top
Show all changes 10 commits https://github.com/python/cpython/pull/9846/files
7602879 Improve list() pre-sizing for inputs with known lengths pablogsal Apr 17, 2018 https://github.com/python/cpython/pull/9846/commits/76028798d0ddef4e6d88c0313db691592bcdd58a
39a8757 Preallocate only when __len__ is available to avoid loss of performan… pablogsal Oct 13, 2018 https://github.com/python/cpython/pull/9846/commits/39a87576b5a3075ec5e0a512065901b436bf8e54
ab450b3 Fix NEWS entry and correct style pablogsal Oct 15, 2018 https://github.com/python/cpython/pull/9846/commits/ab450b3d5a453f36a4988d83b391a79bfbfa5a61
717ca67 Use _PyObject_HasLen to check if the object has lenght to avoid overhead pablogsal Oct 23, 2018 https://github.com/python/cpython/pull/9846/commits/717ca6732b8a15b24542648bdba56812b5ef6867
b678442 Simplify implementation and don't capture all expections on error pablogsal Oct 23, 2018 https://github.com/python/cpython/pull/9846/commits/b67844271da9a4cb3046820be74bf6e0c7b46927
b40bd62 Add assert and fix formatting pablogsal Oct 25, 2018 https://github.com/python/cpython/pull/9846/commits/b40bd623c5536dd90a4cc8ebbc72fc5ff0889ca3
3837486 Remove uneeded test modification pablogsal Oct 25, 2018 https://github.com/python/cpython/pull/9846/commits/38374862963005541cb0af9b7a9beb2c7a98b467
b6ff7ce Don't preallocate if list is modified when calling PyObject_Size pablogsal Oct 26, 2018 https://github.com/python/cpython/pull/9846/commits/b6ff7ce618bc958a4be4cf29aa98a622cf4cebea
e7f8c46 Improve readability in the error handling branch pablogsal Oct 26, 2018 https://github.com/python/cpython/pull/9846/commits/e7f8c464258acf2e82278909fb5e1a792aa65dbf
0a6c8ba Capture only TypeError as suggested by Serhiy pablogsal Oct 28, 2018 https://github.com/python/cpython/pull/9846/commits/0a6c8ba7d2bc269767e0bdbec283b36f59817d22
Clear filters https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
Please reload this pagehttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
Please reload this pagehttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
test_descr.py https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-6b813570d02ae3544e7e0233ae21d647f8e2dc47486495557e8d16c80460e85b
test_list.py https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-af5c4ee62cca27529efe0febc3babfd5745cc1ae48a280a58605a8c85ee38942
2018-04-17-01-24-51.bpo-33234.l9IDtp.rst https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-f69f0dc0516d28a1acd579c1ac914a1044bffcc69ab8387a9dc5ee1c111b7749
listobject.c https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-67a42c5c0990c7aceea040ffc07905299aab97d64dc49adb256f85340b2c7e81
Lib/test/test_descr.pyhttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-6b813570d02ae3544e7e0233ae21d647f8e2dc47486495557e8d16c80460e85b
View file https://github.com/pablogsal/cpython/blob/39a87576b5a3075ec5e0a512065901b436bf8e54/Lib/test/test_descr.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/9846/files/{{ revealButtonHref }}
https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-6b813570d02ae3544e7e0233ae21d647f8e2dc47486495557e8d16c80460e85b
https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-6b813570d02ae3544e7e0233ae21d647f8e2dc47486495557e8d16c80460e85b
Lib/test/test_list.pyhttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-af5c4ee62cca27529efe0febc3babfd5745cc1ae48a280a58605a8c85ee38942
View file https://github.com/pablogsal/cpython/blob/39a87576b5a3075ec5e0a512065901b436bf8e54/Lib/test/test_list.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/9846/files/{{ revealButtonHref }}
https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-af5c4ee62cca27529efe0febc3babfd5745cc1ae48a280a58605a8c85ee38942
https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-af5c4ee62cca27529efe0febc3babfd5745cc1ae48a280a58605a8c85ee38942
Misc/NEWS.d/next/Core and Builtins/2018-04-17-01-24-51.bpo-33234.l9IDtp.rsthttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-f69f0dc0516d28a1acd579c1ac914a1044bffcc69ab8387a9dc5ee1c111b7749
View file https://github.com/pablogsal/cpython/blob/39a87576b5a3075ec5e0a512065901b436bf8e54/Misc/NEWS.d/next/Core%20and%20Builtins/2018-04-17-01-24-51.bpo-33234.l9IDtp.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/9846/files/{{ revealButtonHref }}
vstinnerhttps://github.com/vstinner
Oct 15, 2018https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#r225313835
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
vstinnerhttps://github.com/vstinner
Oct 15, 2018https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#r225313962
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
Objects/listobject.chttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-67a42c5c0990c7aceea040ffc07905299aab97d64dc49adb256f85340b2c7e81
View file https://github.com/pablogsal/cpython/blob/39a87576b5a3075ec5e0a512065901b436bf8e54/Objects/listobject.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/9846/files/{{ revealButtonHref }}
https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-67a42c5c0990c7aceea040ffc07905299aab97d64dc49adb256f85340b2c7e81
serhiy-storchakahttps://github.com/serhiy-storchaka
Oct 23, 2018https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#r227510433
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
Please reload this pagehttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-67a42c5c0990c7aceea040ffc07905299aab97d64dc49adb256f85340b2c7e81
https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-67a42c5c0990c7aceea040ffc07905299aab97d64dc49adb256f85340b2c7e81
vstinnerhttps://github.com/vstinner
Oct 23, 2018https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#r227373110
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
pablogsalhttps://github.com/pablogsal
Oct 23, 2018https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#r227376580
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
vstinnerhttps://github.com/vstinner
Oct 15, 2018https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#r225314645
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54
https://github.com/python/cpython/pull/9846/files/39a87576b5a3075ec5e0a512065901b436bf8e54#diff-67a42c5c0990c7aceea040ffc07905299aab97d64dc49adb256f85340b2c7e81
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.