[antlr-interest] Lazy load of CommonTokenStream??
Kay Röpke
kroepke at classdump.org
Sun Aug 17 14:46:06 PDT 2008
Hi!
On Aug 17, 2008, at 11:04 PM, Gavin Lambert wrote:
> At 08:14 18/08/2008, Jim Idle wrote:
>> Right - so, if size is called a lot then you will add the if to
>> that too. I think that internally size won't be called before
>> something else has already called fillBuffer(). So my point is that
>> we should look at all the paths and cover all the runtime
>> possibilities, then see if it makes sense to have the if in size()
>> - as in, can it be added there without increasing the overall
>> checking done for if (p==0). I found the call to size() to be
>> significant enough that I wanted to optimize it, and while a check
>> for an integer == 0 is quick, it is still overhead.
>
> I suspect that LA() is being called significantly more often than
> size(), so it's probably not a big deal :)
Indeed :)
I just did a quick search for the usages of size() in the Java runtime
and it's in fact called only in toString() methods (for the whole
stream) and in Debug/Profiler stuff.
All of those are really non-critical, because they are either seldomly
used or when debugging one doesn't care for execution time all that
much anyway.
Of course this might not hold true for other runtimes.
I suggest adding fillbuffer and the check to size to minimize the
surprise effect :)
cheers,
-k
--
Kay Röpke
http://classdump.org/
More information about the antlr-interest
mailing list