René's URL Explorer Experiment


Title: Improve import time · Issue #326 · python/importlib_resources · GitHub

Open Graph Title: Improve import time · Issue #326 · python/importlib_resources

X Title: Improve import time · Issue #326 · python/importlib_resources

Description: importlib_resources currently takes a while to import. From rough local testing with whatever Python versions I have installed, the figures are something like this: OS Python Implementation Python Version(s) Import Time (ms) Windows 10 C...

Open Graph Description: importlib_resources currently takes a while to import. From rough local testing with whatever Python versions I have installed, the figures are something like this: OS Python Implementation Python ...

X Description: importlib_resources currently takes a while to import. From rough local testing with whatever Python versions I have installed, the figures are something like this: OS Python Implementation Python ...

Opengraph URL: https://github.com/python/importlib_resources/issues/326

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Improve import time","articleBody":"`importlib_resources` currently takes a while to import. From rough local testing with whatever Python versions I have installed, the figures are something like this:\n\n| OS | Python Implementation | Python Version(s) | Import Time (ms) |\n| ------------- | ------------- | ------------- | ------------- |\n| Windows 10 | CPython | 3.9-3.13 | ~27-37 |\n| Windows 10 | PyPy | 3.10 | ~89 |\n| WSL 2 | CPython | 3.9-3.13 | ~8.5-12.5 |\n\n(The numbers were obtained by cloning the main branch and running `\u003cpython\u003e -m timeit -n 1 -r 1 -- \"import importlib_resources\"` a bunch without a venv, just raw import without site-packages baggage. If need be, I can get more precise results.)\n\nFor context on my perspective, most of the standard library modules that I've interacted with take a fraction of that time.\n\nTo improve this, I've been messing about and managed to get the figures down by at least *7x*:\n\n| OS | Python Implementation | Python Version(s) | Import Time (ms) |\n| ------------- | ------------- | ------------- | ------------- |\n| Windows 10 | CPython | 3.9-3.13 | ~3.5-6.5 |\n| Windows 10 | PyPy | 3.10 | ~5.5 |\n| WSL 2 | CPython | 3.9-3.13 | ~0.6-1.5 |\n\nThis improvement mostly comes from the following:\n1. Replacing the `inspect` usage with a cheaper pattern that other stdlib modules use.\n2. Isolating typing-related symbols and annotations-related symbols so that they are only imported when deferred annotations using them are evaluated (with e.g. `inspect.get_annotations` or `typing.get_type_hints`).\n3. Isolating less-used but very expensive modules/submodules such that they are only imported on demand, i.e. only when deferred annotations containing them are evaluated or functions using them are called.\n4. Consolidating small submodules to avoid reading and compiling several extra files (also, it makes the structure more like `importlib_metadata`'s, imo).\n\nThat's all without a few tricks employed by other standard library modules like `importlib._bootstrap` and `importlib.util`, e.g. avoiding importing `functools` and `contextlib` in exchange for slightly more verbose code. Doing those would make the improvement at least *10x*.\n\nConsidering this is a \"foundational\" library (meant to partially replace the widely used `pkg_resources`) and is also in the standard library, and the potential for improvement is so large with a pretty small amount of effort, I was wondering if there would be interest in improving this, and if so, whether it would be acceptable for me to attempt that by upstreaming some of my work?\n\nP.S. The branch I've been experimenting on is [here](https://github.com/Sachaa-Thanasius/importlib_resources/tree/experiment) if you're curious, though it does too many things (e.g. fixes some bugs, completes the typing, adds unnecessary personalization) for me to consider making a PR with it directly. Makes more sense to do things piecemeal.\n","author":{"url":"https://github.com/Sachaa-Thanasius","@type":"Person","name":"Sachaa-Thanasius"},"datePublished":"2025-03-30T02:53:22.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/326/importlib_resources/issues/326"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:68300f53-be37-80a4-b915-27d3d3a843f8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9DE6:335C13:8B93AE:BE105E:6969DF80
html-safe-nonced4372148cf00adcdd7e472a5290a24c6d25ba4ce710f10d1a2d46b5e8bf62e19
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5REU2OjMzNUMxMzo4QjkzQUU6QkUxMDVFOjY5NjlERjgwIiwidmlzaXRvcl9pZCI6IjEyNzYwOTgyNzc5MTE2ODI5NDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac4220a81a28f66bd5012f82146d727ac0158f181efef31789c007ee703b568c17
hovercard-subject-tagissue:2958625744
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/importlib_resources/326/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f009ca42ec1557cb4376834176573b9aca49f3a6a09c326fc8abc94a2c1f8df3/python/importlib_resources/issues/326
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f009ca42ec1557cb4376834176573b9aca49f3a6a09c326fc8abc94a2c1f8df3/python/importlib_resources/issues/326
og:image:altimportlib_resources currently takes a while to import. From rough local testing with whatever Python versions I have installed, the figures are something like this: OS Python Implementation Python ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameSachaa-Thanasius
hostnamegithub.com
expected-hostnamegithub.com
None7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8
turbo-cache-controlno-preview
go-importgithub.com/python/importlib_resources git https://github.com/python/importlib_resources.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id306147182
octolytics-dimension-repository_nwopython/importlib_resources
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id306147182
octolytics-dimension-repository_network_root_nwopython/importlib_resources
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
releasebdde15ad1b403e23b08bbd89b53fbe6bdf688cad
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/importlib_resources/issues/326#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fimportlib_resources%2Fissues%2F326
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%2Fimportlib_resources%2Fissues%2F326
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%2Fimportlib_resources
Reloadhttps://github.com/python/importlib_resources/issues/326
Reloadhttps://github.com/python/importlib_resources/issues/326
Reloadhttps://github.com/python/importlib_resources/issues/326
python https://github.com/python
importlib_resourceshttps://github.com/python/importlib_resources
Please reload this pagehttps://github.com/python/importlib_resources/issues/326
Notifications https://github.com/login?return_to=%2Fpython%2Fimportlib_resources
Fork 48 https://github.com/login?return_to=%2Fpython%2Fimportlib_resources
Star 70 https://github.com/login?return_to=%2Fpython%2Fimportlib_resources
Code https://github.com/python/importlib_resources
Issues 4 https://github.com/python/importlib_resources/issues
Pull requests 5 https://github.com/python/importlib_resources/pulls
Actions https://github.com/python/importlib_resources/actions
Projects 0 https://github.com/python/importlib_resources/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/importlib_resources/security
Please reload this pagehttps://github.com/python/importlib_resources/issues/326
Insights https://github.com/python/importlib_resources/pulse
Code https://github.com/python/importlib_resources
Issues https://github.com/python/importlib_resources/issues
Pull requests https://github.com/python/importlib_resources/pulls
Actions https://github.com/python/importlib_resources/actions
Projects https://github.com/python/importlib_resources/projects
Security https://github.com/python/importlib_resources/security
Insights https://github.com/python/importlib_resources/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/importlib_resources/issues/326
New issuehttps://github.com/login?return_to=https://github.com/python/importlib_resources/issues/326
Improve import timehttps://github.com/python/importlib_resources/issues/326#top
https://github.com/Sachaa-Thanasius
https://github.com/Sachaa-Thanasius
Sachaa-Thanasiushttps://github.com/Sachaa-Thanasius
on Mar 30, 2025https://github.com/python/importlib_resources/issues/326#issue-2958625744
herehttps://github.com/Sachaa-Thanasius/importlib_resources/tree/experiment
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.