-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Improve ctypes startup time #146547
Copy link
Copy link
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-ctypestype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-ctypestype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)
Feature or enhancement
Proposal:
In the ctypes source, sysconfig is loaded as early as line 5.
However, scanning through the file, it is only used once, and in a conditional branch too:
The reason this is inefficient is that sysconfig imports threading instead of _thread, which cannot be helped since it has to use a top-level RLock. Correct me if I'm wrong, but this means at least 50 ms of import time.
I propose to move the import into this if branch. This may require a backport to 3.13 and 3.14, which have similar inefficiencies. (The import was not present prior.)
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
sysconfig,shutil,subprocessandwarningsmodules #146548