Title: Add caching to logging.Logger.isEnabledFor()
Type: performance Stage: resolved
Components: Library (Lib) Versions: Python 3.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: aviso, pitrou, vinay.sajip, vstinner
Priority: normal Keywords:

Created on 2017-07-18 20:24 by aviso, last changed 2019-08-14 19:55 by zaneb. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2752 merged aviso, 2017-07-18 20:24
PR 15286 closed zaneb, 2019-08-14 19:55
Messages (5)
msg298612 - (view) Author: Avram (aviso) * Date: 2017-07-18 20:24
Checking to see if a log level is enabled can add non-insignificant time to programs with a large number of logging statements. This issue is to track a pull request which introduces caching to the logging module so checking to see if a log level is enabled takes half the current time.

Benchmark code is in the referenced pull request
msg298613 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-07-18 20:34
Does this speed up actual logging calls such, etc?
msg298614 - (view) Author: Avram (aviso) * Date: 2017-07-18 20:44
Yes, though the bottleneck for normal logging is more likely in other areas so the speedup will be less noticeable. Where I notice it is with debug statements when debugging is disabled. In that scenario the bulk of the time is spent checking if the level is enabled anywhere in the ancestry.
msg298615 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-18 20:45
>> Benchmark code is in the referenced pull request
> Does this speed up actual logging calls such, etc?

According to the benchmark in the PR, it's 50% faster when the log is ignored, like a debug call in production.
msg299494 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2017-07-30 09:36
New changeset 78c18a9b9a1445f7c755929917a790ba02b4a5e0 by Vinay Sajip (Avram Lubkin) in branch 'master':
bpo-30962: Added caching to Logger.isEnabledFor() (GH-2752)
Date User Action Args
2019-08-14 19:55:48zanebsetpull_requests: + pull_request15009
2017-07-30 09:44:55vinay.sajipsetstatus: open -> closed
resolution: fixed
stage: resolved
2017-07-30 09:36:36vinay.sajipsetmessages: + msg299494
2017-07-18 20:45:55vstinnersetnosy: + vstinner
messages: + msg298615
2017-07-18 20:44:43avisosetmessages: + msg298614
2017-07-18 20:34:27pitrousetnosy: + pitrou
messages: + msg298613
2017-07-18 20:31:43pitrousetnosy: + vinay.sajip
2017-07-18 20:24:53avisocreate