On Tue, 15 Feb 2005 22:48:28 -0800, Justin Mason <[EMAIL PROTECTED]> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> [de-cc'ing p5p on this one since it's just sa-related.]
Good call. :-)
> > A further
> > optimization would be to outright eliminate the subroutine call so
> > that this would look like:
> >
> > my $lu=$self->{conf}->{scores};
> > if ($lu->{q{__NIGERIAN_BODY_18}}) {
> > #dont call a sub at all, as its faster
> > foreach (@_) {
> > if (/\bSEVERAL ATTEMPTS HAVE BEEN MADE WITH OUT SUCCESS\b/i) {
> > $self->got_pattern_hit (q{__NIGERIAN_BODY_18}, "BODY: ");
> > dbg ("Ran body-text regex rule __NIGERIAN_BODY_18
> > ======> got hit: match='$&'", "rulesrun", 2);
> > # Ok, we hit, stop now.
> > last;
> > }
> > }
> > }
> >
> > Since each subroutine gets called once per line per mail the reduction
> > in call stack overhead should represent a pretty clear run time
> > improvement. I assume this logic is duplicated in the other code
> > generators and not just in the one I was trying to debug.
>
> yep, this is deliberate -- although suboptimal. The idea is so
> that slow-running regexps can be identified with Devel::DProf.
>
> that's a good point btw. both of those should be reconsidered...
> they certainly don't help the runtime speed.
But cant Devel::DProf tell you which lines are running slow? There are
a few tricks to make profiling and debugging evaled subroutines a lot
easier. One trick ive used profitably is to write the subroutine that
will be evaled into existance to a file and then do the file instead
of eval'ing it. That way all the normal tools find the correct line
numbers etc.
Also, i havent reviewed the design closely enough, but I was curious
about one other thing. It would appear that rules arent being added at
run time, or more specifically that the rule code is evaled into
existance only once. This suggests to me that it may be possible to
further optimize the generated code by simply predetermining the
result of the if's at construct time not at run time. Maybe its not
possible though, but in a similar situation ive found such
precalculation is useful.
So all the
if ($lu->{q{__NIGERIAN_BODY_18}})
stuff would be preresolved before the generated code is compiled.
Cheers,
Yves
--
First they ignore you, then they laugh at you, then they fight you,
then you win.
+Gandhi