gh-132372: Speed up logging.config existing logger handling#150242
Open
esadomer wants to merge 1 commit into
Open
gh-132372: Speed up logging.config existing logger handling#150242esadomer wants to merge 1 commit into
esadomer wants to merge 1 commit into
Conversation
Contributor
|
The performance increase is moderate, but the PR reduces code duplication so I am +1. @esadomer On your benchmark I could get a much larger speedud with this small commit 2b9ce22 (on top of your work). I have not fully tested this, but the speedup is > 5x. If you are interested you could test it further and pull into your branch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
gh-132372
This speeds up
logging.config.fileConfig()andlogging.config.dictConfig()when they need to handle many existing loggers whiledisable_existing_loggersis active.The old code kept the existing logger names in a sorted list, but still used repeated list membership,
index(), tail scans, andremove()calls for every configured logger. This keeps the sorted list for child logger ordering, uses a set for membership/removal tracking, and usesbisect_left()to jump directly to the dotted child logger range.Validation:
PCbuild\amd64\python_d.exe -m test test_logging -j0PCbuild\amd64\python_d.exe Tools\patchcheck\patchcheck.pygit diff --checkBenchmark:
Loaded
origin/main:Lib/logging/config.pyand the patchedLib/logging/config.pyinto the same Python 3.12.8 release interpreter, then timed only thedictConfig()call while resetting identical existing logger state outside the timer.