[antlr-interest] Hand made lexer 600(!!!!!) times faster ofANTLR'sone

Richard Matthias richard at exaflop.org
Thu Feb 24 04:18:29 PST 2005


>
>> Really, It is easy to see that during parsing we build tree, then we 
>> kill the whole tree. So having own allocator in ANTLR it is possible 
>> kill the whole tree not as million of delete calls, but as 
>single call 
>> to destroy the whole heap.
>
>Agreed. 
>
>On a related note, I'm interested in ideas about if and how 
>something similar can be achieved in managed langauges (i.e. 
>Java/C#) or do we have to trust the GC?
>
>Micheal

You can use a object pool pattern to avoid constantly allocating and then
abandoning instances. The thing is though that as long as the instances are
caught by generation 0 of the GC, it's very quick as it is. The extra
overhead on the allocation side (allocation from compacted heap is much
faster than typical malloc allocators) and the code necessary to return the
objects to the pool when no longer required is probably more than just
letting the GC do its job. 

It all depends on the rate of garbage creation. There's some rate for a given
system where the GC has to run more frequently than normal to avoid heap
growth. If it runs too frequently that can lead to otherwise short-lived
objects making it into generation 1 which makes them more expensive to
collect later. Clearly it's all going to depend on pattern of allocation
which will depend on the grammar. For C# users, Microsoft have a free tool
called the CLRProfiler which is specifically for analyzing gc behaviour which
might be worth looking at if you think performance is memory related. 

Regards,

richard



More information about the antlr-interest mailing list