This change stops sleekxmpp from spending huge amounts of time unnecessarily computing logging data that may never be used. This is a HUGE performance improvement; in some of my test runs, unnecessary string creation was accounting for > 60% of all CPU time.

Note that using % in a string will _always_ perform the sting substitutions, because the strings are constructed before the function is called. So log.debug('%s' % expensiveoperation()) will take about the same CPU time whether or not the logging level is DEBUG or INFO. if you use , no substitutions are performed unless the string is actually logged
This commit is contained in:
Vijay Pandurangan
2011-11-20 03:30:44 +08:00
committed by Lance Stout
parent 1baf139ca4
commit deb52ad350
23 changed files with 69 additions and 72 deletions

View File

@@ -246,7 +246,7 @@ class BaseXMPP(XMLStream):
spec = "(RFC-%s) " % self.plugin[plugin].rfc
desc = (spec, self.plugin[plugin].description)
log.debug("Loaded Plugin %s%s" % desc)
log.debug("Loaded Plugin %s%s" , desc)
except:
log.exception("Unable to load plugin: %s", plugin)
@@ -282,7 +282,7 @@ class BaseXMPP(XMLStream):
if key in self.plugin:
return self.plugin[key]
else:
log.warning("""Plugin "%s" is not loaded.""" % key)
log.warning("""Plugin "%s" is not loaded.""" , key)
return False
def get(self, key, default):
@@ -679,7 +679,7 @@ class BaseXMPP(XMLStream):
def set_jid(self, jid):
"""Rip a JID apart and claim it as our own."""
log.debug("setting jid to %s" % jid)
log.debug("setting jid to %s" , jid)
self.boundjid.full = jid
def getjidresource(self, fulljid):
@@ -795,7 +795,7 @@ class BaseXMPP(XMLStream):
log.warning('You should catch IqError exceptions')
elif isinstance(exception, IqTimeout):
iq = exception.iq
log.error('Request timed out: %s' % iq)
log.error('Request timed out: %s' , iq)
log.warning('You should catch IqTimeout exceptions')
else:
log.exception(exception)