Why no documentation of basic data structure performance?

David Eppstein eppstein at ics.uci.edu
Tue Feb 12 23:23:41 EST 2002


In article <mailman.1013571621.14946.python-list at python.org>,
 <brueckd at tbye.com> wrote:

> While the info you're talking about can be valuable in some cases, in most
> cases it just doesn't matter, for example, which list operation you use -
> and putting that sort of info in the main documentation encourages us to
> think about optimization when we shouldn't. For example, if I'm not paying
> attention I catch myself doing this too much:
> 
> meth = obj.method
> for item in seq:
>   meth(item)
> 
> Why? Because it saves a lookup to obj.method. But unless I'm trying to
> remove a specific bottleneck I'm solving a non-problem and cluttering my
> code at the same time. Shame on me!

I completely agree about not micro-optimizing until it's necessary,
I was more concerned with situations where the difference between two ways 
of doing things could be much larger (in the case I mentioned, constant 
time vs linear time) and nonobvious (identical wording for the two tutorial 
examples).

> Somebody had a Python optimization page I found useful (was it Skip?) -
> maybe you could report your findings to him/her and have the page updated.
> IMO, that's where this sort of info belongs - on a web page or document
> that we can find when we need it but just far enough out of the way that
> we don't spend too much time looking at it.

Separate documentation per-implementation, somewhere easy to find, sounds 
like a reasonable choice -- another would be to have a few paragraphs here 
and there in the tutorial discussing these issues in the context of the 
major implementations.  Anyway, though, I'm not sure calling it 
optimization matches what I'm thinking of.  My feeling is that choosing the 
right algorithms and data structures is better done before you code, at 
design time, rather than as an optimization after you code -- otherwise you 
may find yourself locked into a solution that's too inefficient or 
inflexible and only able to make minor changes such as the method lookup 
lifting you discuss above.
-- 
David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/



More information about the Python-list mailing list