Disable frozen modules by default, add a toggle #1213
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
python3.11 -Xfrozen_modules=on -c 'pass'
python3.11 -Xfrozen_modules=off -c 'pass'
python3.12 -Xfrozen_modules=on -c 'pass'
python3.12 -Xfrozen_modules=off -c 'pass'
ipykernel import:
python3.11 -Xfrozen_modules=on -c 'import ipykernel'
python3.11 -Xfrozen_modules=off -c 'import ipykernel'
python3.12 -Xfrozen_modules=on -c 'import ipykernel'
python3.12 -Xfrozen_modules=off -c 'import ipykernel'
PYDEVD_DISABLE_FILE_VALIDATION=1 python3.11 -Xfrozen_modules=on -c 'import ipykernel'
PYDEVD_DISABLE_FILE_VALIDATION=1 python3.12 -Xfrozen_modules=on -c 'import ipykernel'
Users can still re-enable freezing modules by passing
--frozen_modules
argument to thepython -m ipykernel install
Existing users will need to regenerate their kernelspec to get the benefit of this change (or add
-Xfrozen_modules=off
manually).