[LLVMdev] Iterator protocols
Talin
viridia at gmail.com
Mon May 12 18:49:06 PDT 2008
This is related to the general question of efficiency of unwinds. I'm
mulling over whether to use the Java-style or Python-style iterator
protocol for my language. The Python style is to have a special
exception (StopIteration) that is thrown when the end of the sequence is
reached. The Java style is to have a separate "hasNext" method on the
iterator object that says whether or not the sequence is finished.
So the question is, what's the trade-off. In most languages that support
exceptions, you tend to think of exceptions as expensive operations that
should only be thrown if something truly "exceptional" happens. OTOH,
the Java case is also made worse by the fact that a large part of the
time you'll be using the more expensive interface dispatching, rather
than simple vtable dispatching.
I would imagine that for smaller sequences the Java protocol wins
(because of the expense of unwinding), whereas for longer sequences the
per-item overhead dominates. The question is, what's the cutoff point
likely to be - how expensive is an unwind compared to, say, a regular
function call. (I haven't tried to measure it because I'm not yet sure
what I am measuring.) I'm just curious if anyone has an opinion on this.
-- Talin
More information about the llvm-dev
mailing list