Skip to content

bpo-45020: Default to using frozen modules only on non-debug builds. #28590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lib/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ def _generate_posix_vars():
if _PYTHON_BUILD:
vars['BLDSHARED'] = vars['LDSHARED']

Py_DEBUG = bool(vars['Py_DEBUG'])
vars['FROZEN_MODULES_DEFAULT'] = 0 if Py_DEBUG else 1

# There's a chicken-and-egg situation on OS X with regards to the
# _sysconfigdata module after the changes introduced by #15298:
# get_config_vars() is called by get_platform() as part of the
Expand Down Expand Up @@ -490,6 +493,10 @@ def _init_non_posix(vars):
vars['VERSION'] = _PY_VERSION_SHORT_NO_DOT
vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable))
vars['TZPATH'] = ''
# infer build vars
Py_DEBUG = hasattr(sys, 'gettotalrefcount')
vars['Py_DEBUG'] = 1 if Py_DEBUG else 0
vars['FROZEN_MODULES_DEFAULT'] = 0 if Py_DEBUG else 1

#
# public APIs
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@
STDLIB_DIR = os.path.dirname(TEST_HOME_DIR)
REPO_ROOT = os.path.dirname(STDLIB_DIR)

Py_DEBUG = hasattr(sys, 'gettotalrefcount')


class Error(Exception):
"""Base class for regression test exceptions."""
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'pathconfig_warnings': 1,
'_init_main': 1,
'_isolated_interpreter': 0,
'use_frozen_modules': 0,
'use_frozen_modules': 0 if support.Py_DEBUG else 1,
}
if MS_WINDOWS:
CONFIG_COMPAT.update({
Expand Down
7 changes: 5 additions & 2 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -2089,9 +2089,12 @@ config_init_import(PyConfig *config, int compute_path_config)
/* -X frozen_modules=[on|off] */
const wchar_t *value = config_get_xoption_value(config, L"frozen_modules");
if (value == NULL) {
// For now we always default to "off".
// In the near future we will be factoring in PGO and in-development.
// Default to "off" on debug builds and "on" otherwise.
#ifdef Py_DEBUG
config->use_frozen_modules = 0;
#else
config->use_frozen_modules = 1;
#endif
}
else if (wcscmp(value, L"on") == 0) {
config->use_frozen_modules = 1;
Expand Down