Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Reduce debug logging overhead #6251

Merged
merged 5 commits into from
Oct 25, 2019
Merged

Conversation

michaelkaye
Copy link
Contributor

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file
  • Pull request includes a sign off

I'm not sure how much CPU this would likely save us, but I believe that the following three commits are safe and can avoid some formatting when not needed:

  • encode_canonical_json is not a trivial operation for debug logging (we do it twice - before and after we sign the event)
  • log.debug("%s", repr(obj)) => log.debug("%r", obj) will save calling repr() unless needed
  • log.debug("%s, %s" % (obj1,obj2)) => log.debug("%s, %s", obj1, obj2) will save string formatting unless needed

Hopefully in the worst case they're just noop changes.

I believe that string formatting ~10-15 sized events will
take a proportion of CPU time.
This avoids calculating __repr__ unless we are going to log.
Using % will cause the string to be generated even if debugging
is off.
@michaelkaye michaelkaye requested a review from a team October 24, 2019 17:47
@erikjohnston erikjohnston merged commit 44ab048 into develop Oct 25, 2019
babolivier pushed a commit that referenced this pull request Sep 1, 2021
* commit '44ab048cf':
  Address codestyle concerns
  Reduce impact of debug logging
  Delay printf until logging is required.
  use %r to __repr__ objects
  Don't encode object as UTF-8 string if not needed.
@DMRobertson DMRobertson deleted the michaelkaye/debug_guard_logging branch June 28, 2022 11:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants