Version française
Home     About     Download     Resources     Contact us    
Browse thread
Strange performance bug
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brighten Godfrey <pbg@c...>
Subject: Re: [Caml-list] Strange performance bug
On Apr 28, 2009, at 8:37 PM, Markus Mottl wrote:
> On Tue, Apr 28, 2009 at 22:43, Brighten Godfrey  
> <pbg@cs.berkeley.edu> wrote:
>> I've encountered a very odd performance problem which I suspect is  
>> not a bug
>> in my code.  Could it be the compiler, or maybe PCRE?
>
> I'm not sure it solves your problem (haven't tried the example), but
> just looking at the code there is clearly a performance bug: the
> pattern is passed to Pcre.pmatch "on the fly" using label "~pat".
> This is ok and convenient if it is used only once, but is bad if it
> happens in a loop.  Precompile the regular expression outside of the
> loop (let rex = Pcre.regexp "...") and pass it in with label "~rex" to
> solve this problem.


I can't see how this explains the problem.  Why should the parsing get  
dramatically slower when starting to parse the file a *second* time?

(Changing to the precompiled regexp does make this bug go away -- but  
so do many other small changes, like commenting out the last line of  
the code, *after* the parsing is complete.)

Thanks very much,
~Brighten