Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Slow module problem?

Status
Not open for further replies.

michaeljiang

Programmer
Aug 4, 2007
5
US
I have a class moduel A.pm, a non-class module B.pm and a console file C.pl.

This is relationship of these 3:

C.pl "use B;"
B.pm "use A;" and "new A();"

In "new" of A.pm, I have some codes to read a file for about 240000 lines.

But it took extremely long time ( more than 5 minutes!) for A.pm to finish reading those 240000 lines in "new".

I tested to just "new A()" from command line and from a simple perl file that only does this. It finishes in a second.

I'm confused and "perl -d" didn't help much to tell why it takes long time. "perl -d:DProf" and "dprofpp" did show that the "new" subroutine takes long time and it also shows: "Exporter::as_heavy" and "DynaLoader::BEGIN"(which I didn't explicitly call in my program at all). But I cannot find a clue what might be the cause.

Any thoughts?

Thanks!
 
Forgot to mention, in "new" of A.pm, it first opens a file and read all lines into a variable ONCE. Then it has a while loop to iterate all lines to do some processing. It is this while loop that cost that long time.
 
Post the perl code and maybe someone will have a suggestion about what is causing the dealy. I doubt that rhe fact that C calls B calls A and constructs a new object is the reason it takes that long.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Solved finally.

In the while loop (in "new" of "A.pm"), I used regular expression to look for certain patterns. Unfortunately, in "B.pm", "English" module is used and that was included long time ago for test purpose (yes, unfortunately, it is still there, BAD:( and I didn't notice it twice for this problem. Now, I check all modules used to locate where the problem is and realized that it caused this performance problem.

This is a reminder to anyone who happens to use this module "English", from its documentation:

PERFORMANCE ^

This module can provoke sizeable inefficiencies for regular expressions, due to unfortunate implementation details. If performance matters in your application and you don't need $PREMATCH, $MATCH, or $POSTMATCH, try doing

use English qw( -no_match_vars ) ;

. It is especially important to do this in modules to avoid penalizing all applications which use them.
 
A very subtle, but very vicious bug. Good catch.

- M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top