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: micro optimization for import_all_from
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, serhiy.storchaka, vstinner, xiang.zhang
Priority: normal Keywords: patch

Created on 2016-09-20 17:06 by xiang.zhang, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
import_all_from.patch xiang.zhang, 2016-09-20 17:06 review
Messages (2)
msg277046 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-09-20 17:06
Since PyMapping_Keys always return a list or tuple and most __all__s are list (all in stdlib), I think we can avoid calling PySequence_GetItem for every key and use PySequence_Fast* APIs instead. This doesn't help much since other operations involved are expensive.

With patch:

[bin]$ ./python3 -m perf timeit -s 'import _ast; code=compile("from _ast import *", "<string>", "exec")' 'exec(code)'
....................
Median +- std dev: 11.3 us +- 0.3 us
[bin]$ ./python3 -m perf timeit -s 'import zipfile; code=compile("from zipfile import *", "<string>", "exec")' 'exec(code)'
....................
Median +- std dev: 2.98 us +- 0.04 us

Without patch:

[bin]$ ./python3 -m perf timeit -s 'import _ast; code=compile("from _ast import *", "<string>", "exec")' 'exec(code)'
....................
Median +- std dev: 12.5 us +- 0.3 us
./python3 -m perf timeit -s 'import zipfile; code=compile("from zipfile import *", "<string>", "exec")' 'exec(code)'
....................
Median +- std dev: 3.09 us +- 0.06 us
msg277054 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-09-20 18:07
As pointed out by Serhiy, PyObject_GetAttr may change __all__ so my proposal is not going to work. Close this and sorry for noise. :-(
History
Date User Action Args
2022-04-11 14:58:37adminsetgithub: 72403
2016-09-20 18:07:27xiang.zhangsetstatus: open -> closed
resolution: rejected
messages: + msg277054

stage: patch review -> resolved
2016-09-20 17:06:40xiang.zhangcreate