Hi,
I'm currently working on speeding up the legend rendering of matplotlib
as this turns out to be a bottleneck for my application. With some
tracing and profiling, I found that
matplotlib.__init__.RcParams.__getitem__() makes up around 10% of the
total function calls (by number) in my little test program. It is called
continuously all over the matplotlib code, whenever a configuration
parameter is accessed.
Therefore removed the __getitem__ method and moved the key validation to
a newly written __init__ function, so that validation only happens once
the object is created, and otherwise the native lookup of the dict()
class is used. This made my program around 10% faster! :-)
The diff ("svn diff") is appended. If you are interested in the
profiling results (not only regarding this piece of code), please let me
know!
Hope that helps!
Dieter
Index: lib/matplotlib/__init__.py
===================================================================
--- lib/matplotlib/__init__.py (Revision 8705)
+++ lib/matplotlib/__init__.py (Arbeitskopie)
@@ -636,6 +636,32 @@
defaultParams.iteritems() ])
msg_depr = "%s is deprecated and replaced with %s; please use the latter."
msg_depr_ignore = "%s is deprecated and ignored. Use %s"
+
+ def __init__(self, arg, **kw):
+ newarg = []
+ newkw = {}
+ for (key, val) in arg:
+ if key in _deprecated_map.keys():
+ alt = _deprecated_map[key]
+ warnings.warn(self.msg_depr % (key, alt))
+ newarg.append((alt, val))
+ elif key in _deprecated_ignore_map:
+ alt = _deprecated_ignore_map[key]
+ warnings.warn(self.msg_depr_ignore % (key, alt))
+ continue
+ newarg.append((key, val))
+
+ for (key, val) in kw.iteritems():
+ if key in _deprecated_map.keys():
+ alt = _deprecated_map[key]
+ warnings.warn(self.msg_depr % (key, alt))
+ newkw[alt] = val
+ elif key in _deprecated_ignore_map:
+ alt = _deprecated_ignore_map[key]
+ warnings.warn(self.msg_depr_ignore % (key, alt))
+ continue
+ newkw[key] = val
+ super(RcParams, self).__init__(newarg, **newkw)
def __setitem__(self, key, val):
try:
@@ -653,17 +679,6 @@
raise KeyError('%s is not a valid rc parameter.\
See rcParams.keys() for a list of valid parameters.' % (key,))
- def __getitem__(self, key):
- if key in _deprecated_map.keys():
- alt = _deprecated_map[key]
- warnings.warn(self.msg_depr % (key, alt))
- key = alt
- elif key in _deprecated_ignore_map:
- alt = _deprecated_ignore_map[key]
- warnings.warn(self.msg_depr_ignore % (key, alt))
- key = alt
- return dict.__getitem__(self, key)
-
def keys(self):
"""
Return sorted list of keys.
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel