At 11:19 AM 9/17/2001 +0800, Rajeev Rumale wrote:
>Hello EveryBody
>
>I needed some advice for all.
>
>I am working on a untilty which needs to perform server functions.
>
>I am bit confused with compliation sequency of scripts, when we use "do",
>"require" or "use" to include into our scripts.
>
>I have written a library  file which contains all the common routines, and
>include this in evey other script i write.
>
>This file is very very long running around 3000 lines.  But most of the
>scripts use around 10% of the libraray routines only.

Well, considering that CGI.pm is 6400 lines long and that includes yet 
other modules etc, I don't know if you should be worried about 3000 lines.

However, if most scripts use only 10% of the library routines, you might 
consider looking into a feature called AUTOLOAD and require the second 
library to instantiate the routines that are called less often.

>As per my understanding when ever any script is invoked it will complie both
>the script and the included files.  This is done each time the script is
>invoke.

Not necessarily. use is always loading the modules at compile time. But 
require is only hit at run-time so you can selectively break up your 
library and only require the library or module "on-demand". AUTOLOAD is 
something you should look into though.

>I would like to know if I can group this subroutines into different files
>and include only the relevant routines an and when required depending upon
>coditions at runtime.
>
>This will keep the files size to be less and will also avoid unnecessary
>compilation time.


You should definitely consider refactoring a little bit to make sure that 
routines that are alike are grouped together. However, IMHO refactoring the 
library code just on how often the routines are called is not good in the 
long term.

I appreciate that you want to improve the performance of your CGI, but 300 
lines of code versus 2700 lines of code being loaded later is not going to 
make a big difference to the overall performance when you consider the many 
other libraries you are probably loading (and may not even know it!).

Second, refactoring based on how often the code is used rather than based 
on grouping them by like-task will be guaranteed to make your life a 
headache as you add and subtract routines as your requirements change for 
what the application is supposed to do (and any good program will change 
over time).

If performance is really your primary concern, I would sooner recommend 
that you split your code up by like functions, not for "loading time" and 
then for performance increase use mod_perl, Speedy::CGI or any other number 
of environments that can compile your code once but just keep it in memory 
for the future.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to