Patch for matplotlib.__init__ for speedup

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! :slight_smile:

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

matplotlib.diff (2.11 KB)

First glance looks alright to me, though I haven't looked in heavy
detail. I will defer, however, to those much more familiar with this
code.

Thanks for the patch,

Ryan

ยทยทยท

On Mon, Sep 20, 2010 at 6:04 PM, Dieter Weber <dieter@...887...> wrote:

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! :slight_smile:

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!

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma