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

Speed up logging.getLogger() for already-registered loggers · Issue #150818 · python/cpython · GitHub

Repository navigation

Speed up logging.getLogger() for already-registered loggers #150818

Closed

Description

logging.getLogger(name) returns the singleton logger for a name, creating it on first use. Every call takes the logging lock, even the overwhelmingly common case where the logger already exists and is returned unchanged.

Libraries fetch their logger by name throughout their code — at module import and often again inside functions — so the same handful of names are looked up over and over for the lifetime of a process. These repeat lookups are pure overhead: the logger is already there.

Resolving logger names collected from the top-1000 corpus takes 6.68 µs today and 5.02 µs with a lock-free fast path for the already-registered case, 33% faster. First-time creation, placeholder resolution and the parent/child wiring still run under the lock exactly as before, and the fast path relies only on an atomic dict lookup so it is safe under both the GIL and free threading.

Linked PRs

Activity

  1. added 2 commits that reference this issue on Jun 2, 2026
  2. added
    type-featureA feature request or enhancement
    performancePerformance or resource usage
    stdlibStandard Library Python modules in the Lib/ directory
    on Jun 3, 2026
  3. added a commit that references this issue on Jun 4, 2026
  4. merwok commented on Jun 5, 2026

    Member

    Libraries fetch their logger by name throughout their code — at module import and often again inside functions

    Surprised to read this! I am familiar with the module-level instantiation idiom.

  5. added a commit that references this issue on Jun 5, 2026
  6. added a commit that references this issue on Jun 5, 2026
  7. added 2 commits that reference this issue on Jun 17, 2026
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

    performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL