New submission from Eric Snow <ericsnowcurren...@gmail.com>:

tl;dr let's move PyInterpreterState.config to _PyRuntimeState.config.

Historically the runtime has been initialized using Py_Initialize().  PEP 587 
added Py_InitializeFromConfig(), which takes a PyConfig and allows all sorts of 
customization of the runtime.  This is valuable for embedders (and benefits 
core development too).

During runtime initialization the given config is copied and stored internally 
on the main interpreter.  Once initialization completes, the config is no 
longer modified.  The config values are then used in a variety of places during 
execution.  If a new interpreter is created then the config from the current 
(or main) interpreter are copied into it.

Note the following:

* the config is never modified
* there is no public API for getting the config or changing it
* there is no API for creating an interpreter with a different config
* the fact that the config is stored on the interpreter is an internal detail 
and not documented (nor discussed in PEP 587)

Consequently, PyConfig really is the global runtime config.  Yet we are storing 
a copy of it on each interpreter.  Doing so unnecessarily adds extra complexity 
(and, when multiple interpreters are used, extra CPU usage and extra memory 
usage).

So I propose that we move the config to _PyRuntimeState.  The change isn't big 
nor all that complex.  Note that actually there is one field that can differ 
between interpreters: PyConfig._isolated_interpreter (set in 
_Py_NewInterpreter()).  We can move that one field to a new per-interpreter 
config struct.

----------
assignee: eric.snow
components: C API, Interpreter Core
messages: 414772
nosy: eric.snow, vstinner
priority: normal
severity: normal
stage: needs patch
status: open
title: The global config should not be stored on each interpreter
versions: Python 3.11

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46964>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to