FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Optimizer calls `getenv` on every optimization run · Issue #116772 · python/cpython · GitHub

Repository navigation

Optimizer calls getenv on every optimization run #116772

Closed

Description

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    performancePerformance or resource usage
    on Mar 14, 2024
  2. ronaldoussoren commented on Mar 16, 2024

    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.

  3. savannahostrowski commented on Jan 23, 2026

    Member

    This issue seems to have been resolved by #144082, which moved PYTHON_UOPS_OPTIMIZE to the _PyOptimizationConfig. The environment variable is now read once during interpreter initialization in pystate.c and cached in interp->opt_config.uops_optimize_enabled so we aren't calling getenv() for this flag during optimization runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL