Skip to content
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

Optimizer calls getenv on every optimization run #116772

Open
mdboom opened this issue Mar 14, 2024 · 1 comment
Open

Optimizer calls getenv on every optimization run #116772

mdboom opened this issue Mar 14, 2024 · 1 comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage type-bug An unexpected behavior, bug, or error

Comments

@mdboom
Copy link
Contributor

mdboom commented Mar 14, 2024

Bug report

Bug description:

The optimizer currently calls getenv during every optimization attempt. This has a small, but statistically significant 0.5% impact on performance. Do we need to do this each time, or could we read it to a flag during initialization?

diff --git a/Python/optimizer.c b/Python/optimizer.c
index 88c45f2e73c..b55556d30ab 100644
--- a/Python/optimizer.c
+++ b/Python/optimizer.c
@@ -1010,8 +1010,7 @@ uop_optimize(
         return err;
     }
     OPT_STAT_INC(traces_created);
-    char *env_var = Py_GETENV("PYTHON_UOPS_OPTIMIZE");
-    if (env_var == NULL || *env_var == '\0' || *env_var > '0') {
+    if (true) {
         err = _Py_uop_analyze_and_optimize(frame, buffer,
                                            UOP_MAX_TRACE_LENGTH,
                                            curr_stackentries, &dependencies);

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

@mdboom mdboom added type-bug An unexpected behavior, bug, or error performance Performance or resource usage labels Mar 14, 2024
@ronaldoussoren
Copy link
Contributor

IMHO options should be processed using the PyConfig interface, that way all configuration stays in a central place and it is easier for embedders to change this setting. Also: With the current code there's no way to enable this option when using python -E.

@picnixz picnixz added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants