Are you referring to https://hub.docker.com/_/python? These are “Docker Official Images”, not official Python images. The images are provided by Docker Community, not by the PSF or Python community.
A while ago debian started to build python without using a libpython.
They claimed that that change made starting python faster.
May be that is the difference?
Otherwise it could be differences in compiler optimisation options used.
The “benchmark” I’ve used does not measure python boot time, only code execution. The difference is not here.
I’ve checked python build args using sysconfig.get_config_vars('CONFIG_ARGS')
Debian ones :
It compare python from different Linux distributions using docker and local Python.
Here are the results on my machine which run Arch Linux: (percent are diff with official Docker’s Python)
What matters are the C compiler used, gcc I would expect, and the C compiler options.
Even if --enable-optimisations is not passed to python configure script that does mean there are no optimisations. Its typical to pass them in env vars like CFLAGS and LDFLAGS.
Do you know what they where when python was compiled?
No, your answer wrong. --enable-optimization is used for PGO builds, which makes Python about 10% faster. PGO cannot be enabled by passing different CFLAGS and LDFLAGS alone. In PGO mode, make first compiles an instrumented build of Python, then runs some tests to create optimization profiles, and finally compiles Python a second time. You trade a slower build for a faster Python.
You can get the actual flags for Python interpreter core from sysconfig.get_config_vars("PY_CORE_CFLAGS") and sysconfig.get_config_vars("PY_CORE_LDFLAGS"). Fedora and RHEL use additional flags like -fno-semantic-interposition, which can increase performance by up to 30% with Python 3.8. AFAIK speedups are less impressive in 3.12.