This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Speed up import from non-packages
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, eric.snow, ncoghlan, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2018-02-25 08:46 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 5873 merged serhiy.storchaka, 2018-02-25 09:05
Messages (2)
msg312781 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-02-25 08:46
The proposed PR optimizes "from ... import ..." from non-package modules.

$ ./python -m perf timeit 'from locale import getlocale'
Unpatched:  Mean +- std dev: 811 ns +- 27 ns
Patched:    Mean +- std dev: 624 ns +- 17 ns

Currently _bootstrap._handle_fromlist() is called which does nothing if the module is not a package, but adds an overhead of calling a Python function. The PR moves this check out of _handle_fromlist and avoid calling it if not needed.
msg313587 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-03-11 08:52
New changeset 4e2442505c5e9eec396dcef4d2e6bdd2b6f92fc9 by Serhiy Storchaka in branch 'master':
bpo-32946: Speed up "from ... import ..." from non-packages. (GH-5873)
https://github.com/python/cpython/commit/4e2442505c5e9eec396dcef4d2e6bdd2b6f92fc9
History
Date User Action Args
2022-04-11 14:58:58adminsetgithub: 77127
2018-03-11 08:58:13serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-03-11 08:52:41serhiy.storchakasetmessages: + msg313587
2018-02-25 09:05:43serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request5646
2018-02-25 08:46:54serhiy.storchakacreate