Skip to content

Conversation

@krassowski
Copy link
Member

@krassowskikrassowski commented Feb 14, 2024

Fixes#1198

Frozen modules were extended to modules imported by cPython on startup and enabled by default with the intend of improving startup performance by up to 15% (see python/cpython#28335)

I would suggest we disable frozen modules by default because the performance difference in startup time is ~1% for ipykernel (4 to 5ms compared to total startup time of ~430ms) and this prevents user from getting difficult to diagnose errors during debugging. Of note the same 5ms makes for ~3% of plain Python startup time in 3.11.

Local micro benchmark (1000 repeats each) on Python 3.11 and 3.12.2 (using hyperfine).

Plain Python startup:

CommandMean [ms]Min [ms]Max [ms]Relative
python3.11 -Xfrozen_modules=on -c 'pass'155.3 ± 16.8138.5315.11.00
python3.11 -Xfrozen_modules=off -c 'pass'159.5 ± 18.8140.9371.21.03 ± 0.16
python3.12 -Xfrozen_modules=on -c 'pass'138.2 ± 13.3124.9338.81.00
python3.12 -Xfrozen_modules=off -c 'pass'141.6 ± 11.5128.5281.91.02 ± 0.13
Details
hyperfine --runs 1000 "python -Xfrozen_modules=on -c 'pass'""python -Xfrozen_modules=off -c 'pass'" --export-markdown x_frozen_on_off_plain_python_pass_1000.md

ipykernel import:

CommandMean [ms]Min [ms]Max [ms]Rel.
python3.11 -Xfrozen_modules=on -c 'import ipykernel'428.0±33.0382.5648.21.00
python3.11 -Xfrozen_modules=off -c 'import ipykernel'432.4±33.3388.5633.51.01 ± 0.11
python3.12 -Xfrozen_modules=on -c 'import ipykernel'468.0±30.5423.7750.61.00
python3.12 -Xfrozen_modules=off -c 'import ipykernel'472.4±29.3425.8664.51.01 ± 0.09
Details
hyperfine --runs 1000 "PYDEVD_DISABLE_FILE_VALIDATION=1 python -Xfrozen_modules=on -c 'import ipykernel'""python -Xfrozen_modules=on -c 'import ipykernel'""python -Xfrozen_modules=off -c 'import ipykernel'" --export-markdown x_frozen_on_off_ipykernel_import_1000.md
CommandMean [ms]Min [ms]Max [ms]Relative
PYDEVD_DISABLE_FILE_VALIDATION=1 python3.11 -Xfrozen_modules=on -c 'import ipykernel'427.0 ± 30.9383.4642.71.00
PYDEVD_DISABLE_FILE_VALIDATION=1 python3.12 -Xfrozen_modules=on -c 'import ipykernel'471.1 ± 36.1425.3751.11.01 ± 0.10

Users can still re-enable freezing modules by passing --frozen_modules argument to the python -m ipykernel install

Existing users will need to regenerate their kernelspec to get the benefit of this change (or add -Xfrozen_modules=off manually).

@krassowski
Copy link
MemberAuthor

I think the downstream test failure is due to a flaky test as it was passing on my fork.

Copy link
Contributor

@blink1073blink1073 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@blink1073blink1073 enabled auto-merge (squash) February 15, 2024 02:24
@blink1073blink1073 merged commit eddd3e6 into ipython:mainFeb 15, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

python 3.11 debugpy error messages

2 participants

@krassowski@blink1073