[Python-Dev] Store startup modules as C structures for 20%+ startup speed improvement?
nas-python at arctrix.com
Sun Sep 16 16:13:53 EDT 2018
On 2018-09-15, Paul Moore wrote:
> On Fri, 14 Sep 2018 at 23:28, Neil Schemenauer <nas-python at arctrix.com> wrote:
> > We could have a new format, .pya (compiled python archive) that has
> > data for many .pyc files in it.
> Isn't that essentially what putting the stdlib in a zipfile does? (See
> the windows embedded distribution for an example). It probably uses
> normal IO rather than mmap, but maybe adding a "use mmap" flag to the
> zipfile module would be a more general enhancement that zipimport
> could use for free.
Yeah, it's close to the same thing. If the syscalls are what gives
the speedup, using a better zipfile implementation might give nearly
the same benefit.
At the sprint we dicussed a variation of Larry's (FB's) patch.
Allow the frozen data to be in DLLs as well as in the python
executable data segment. So, importlib would be frozen into the
exe. The standard library could become another DLL. The user could
provide one or more DLLs that contains their app code and package
deps. In general, I think there would only be two DLLs: stdlib and
My suggestion of a special format (similar to zipfile) was
motivated by the wish to avoid platform build tools. E.g. Windows
users would have a harder time to build DLLs. However, I now think
depending on platform build tools is fine. The people who will
build these DLLs will have the tools and skills to do so. Even if
there is only a DLLs for the stdlib, it will be a win. If no DLLs
are provided, you get the same behavior as current Python (i.e.
importlib is frozen in, everything else can come from .py files).
I think there is no question that Larry's PR will be faster than the
zipfile approach. It removes the umarshal step. Maybe that benefit
will but small but I think it should count. Also, I suspect the OS
can page-in the DLL on-demand and perhaps leave parts of module .pyc
data on disk. Larry had the idea of keeping code objects frozen
until they need to be executed. It's a cool idea that would be
enabled by this first step.
I'm excited about Larry's PR. I think if we get it cleanup up and
into Python 3.8, we will clearly leave Python 2.7 behind in terms of
startup performance. That has been a goal of mine for a couple
More information about the Python-Dev