[Python-Dev] Python startup time (original) (raw)
Stefan Behnel stefan_ml at behnel.de
Thu Jul 20 09:32:48 EDT 2017
- Previous message (by thread): [Python-Dev] Python startup time
- Next message (by thread): [Python-Dev] Python startup time
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Ivan Levkivskyi schrieb am 20.07.2017 um 13:24:
I agree the start-up time is important. There is something that is related. ABCMeta is currently implemented in Python. This makes it slow, creation of an ABC is 2x slower than creation of a normal class. However, ABCs are used by many medium and large size projects. Also, both abc and collectionsabc are imported at start-up (in particular importlib uses several ABCs, os also needs them for environments). Finally, all generics in typing module and user-defined generic types are ABCs (to allow interoperability with collections.abc).
My idea is to re-implement ABCMeta (and ingredients it depends on, like WeakSet) in C.
I know that this hasn't really been an accepted option so far (and it's actually not an option for a few really early modules during startup), but compiling a Python module with Cython will usually speed it up quite noticibly (often 10-30%, sometimes more if you're lucky, e.g. [1]). And that also applies to the startup time, simply because it's pre-compiled.
So, before considering to write an accelerator module in C that replaces some existing Python module, and thus duplicating its entire source code with highly increased complexity, I'd like to remind you that simply compiling the Python module itself to C should give at least reasonable speed-ups without adding to the maintenance burden, and can be done optionally as part of the build process. We do that for Cython itself during its installation, for example.
Stefan (Cython core developer)
[1] 3x faster URL routing by compiling a single Django module with Cython: https://us.pycon.org/2017/schedule/presentation/693/
- Previous message (by thread): [Python-Dev] Python startup time
- Next message (by thread): [Python-Dev] Python startup time
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]