Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » IMP » Possible performance bug in LPG?
Possible performance bug in LPG? [message #575560] Wed, 24 June 2009 18:22
Dieter Kleinrath is currently offline Dieter KleinrathFriend
Messages: 5
Registered: July 2009
Junior Member
While trying to improve the performance of my LPG parser I think I found=
a =

serious performance bug in LPG.
Actually I can not believe that this wasn't mentioned before so if this =
is =

known or if it is intended behaviour please appologize.

The problem arises if the same generated parser is reused to parse sever=
al =

files. When a file is parsed with lpg.runtime.DeterministicParser it fir=
st =

calls the method lpg.runtime.Stacks.reallocateStacks(). Here is the code=

from this method:

int old_stack_length =3D (stateStack =3D=3D null ? 0 : =

stack_length =3D old_stack_length + STACK_INCREMENT;

if (stateStack =3D=3D null)
stateStack =3D new int[stack_length];
locationStack =3D new int[stack_length];
parseStack =3D new Object[stack_length];
System.arraycopy(stateStack, 0, stateStack =3D new =

int[stack_length], 0, old_stack_length);
System.arraycopy(locationStack, 0, locationStack =3D new =

int[stack_length], 0, old_stack_length);
System.arraycopy(parseStack, 0, parseStack =3D new =

Object[stack_length], 0, old_stack_length);

As you can see if the stateStack was already created, the parser will co=
py =

its contents into a new array with the size =

old_stack_length+STACK_INCREMENT. This is done because the =

reallocateStacks() method is also used to resize the stack when needed. =

This behaviour results in a memory leak and in serious performance =

problems when reusing a parser instance for compiling more than one file=
.. =

After I changed my code to not reuse the parser the compilation time for=

about 200 files was reduced from 10 seconds to under one second so it is=

now 10 times faster.

The ParseController that gets generated by IMP also lazily instantiates =

the internal DeterministicParser. So perhaps IMP suffers the same =

performance problems (I'm not sure if IMP reuses the ParseController).

If someone can confirm that this is a bug I'll create a bug report for i=

Previous Topic:LPG Options Wiki
Next Topic:Error handling - where to define messages
Goto Forum:

Current Time: Tue Feb 09 22:49:37 GMT 2016

Powered by FUDForum. Page generated in 0.01658 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software