Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve performance in DictConfigurator by optimizing logger lookup #132372

Open
Labels
performancePerformance or resource usagestdlibPython modules in the Lib dirtype-featureA feature request or enhancement
@allrob23

Description

@allrob23

Feature or enhancement

Proposal:

In logging.config.DictConfigurator.configure() (in Lib/logging/config.py), the current implementation uses a list called existing to store logger names:

existing=list(root.manager.loggerDict.keys())existing.sort()

This list is then used in both anif name in existing check and anexisting.index(name) call:

ifnameinexisting:i=existing.index(name)

Both operations are O(n) on a list. While this likely isn’t a major performance bottleneck for a small number of loggers, it could be avoided — and the change would be a net gain in efficiency.

One idea would be to build a set_existing = set(existing) for O(1) membership checks, and possibly a dict_existing = {name: idx} to avoid linear-time indexing, while keeping the original sorted list for the required prefix-based logic:

existing=list(root.manager.loggerDict.keys())existing.sort()existing_set=set(existing)index_map= {name:idxforidx,nameinenumerate(existing)}

Then the logic becomes:

ifnameinexisting_set:i=index_map[name]

This avoids repeated linear scans without changing existing behavior.

Would this kind of change be reasonable here, or is there a better approach you’d recommend for balancing performance and clarity?

Happy to draft a PR if the direction makes sense.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagestdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp