3 ms·
Oh, there's been plenty of work to reduce the Python startup cost. It's just hard to fix. I'm not sure the os.environ example I gave is low-hanging fruit now.
by eesmith 7y ago
Oh, there's been plenty of work to reduce the Python startup cost.
It's just hard to fix.
I'm not sure the os.environ example I gave is low-hanging fruit now. The collections.abc module might be imported anyway.
This is neat! Python 3.7 added the `PYTHONPROFILEIMPORTTIME=1` environment variable to help track down these sorts of import overheads:
% env PYTHONPROFILEIMPORTTIME=1 python -c pass
import time: self [us] | cumulative | imported package
import time: 523 | 523 | zipimport
import time: 722 | 722 | _frozen_importlib_external
import time: 156 | 156 | _codecs
import time: 2254 | 2409 | codecs
import time: 1293 | 1293 | encodings.aliases
import time: 7192 | 10893 | encodings
import time: 1108 | 1108 | encodings.utf_8
import time: 182 | 182 | _signal
import time: 1069 | 1069 | encodings.latin_1
import time: 395 | 395 | _abc
import time: 1486 | 1881 | abc
import time: 1540 | 3420 | io
import time: 100 | 100 | _stat
import time: 975 | 1075 | stat
import time: 1481 | 1481 | genericpath
import time: 1734 | 3214 | posixpath
import time: 2558 | 2558 | _collections_abc
import time: 2234 | 9079 | os
import time: 1407 | 1407 | _sitebuiltins
import time: 3498 | 3498 | sitecustomize
import time: 85 | 85 | usercustomize
import time: 4129 | 18196 | site
Investigating further, the "import os" which triggered the UserDict/collections.abc is a consequence of "import site". If I use "python -S" then those aren't imported.