Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Description
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