in reply to large perl module
Indeed a hash is the fastest way of looking up that data, but do you really need split millisecond speed?
Also, keeping the data in the module itself is wasteful of memory: once the module has finished loading and compiling, you now have the whole of the module in memory PLUS the data in some variables. If you go for the data to be loaded from a data-file (say a YAML or JSON file) then you can save at least the amount of data you now store in your module.
Update:I now note that your module runs in a "mod_perl" environment. You have to be very careful in designing your programs so that you avoid the big module being private to each child process, since these child processes are regularly reaped and respawned by the web-server (see the Apache MaxRequestsPerChild Directive) and thus will reload your big module again and again and again. Ideally your data-structure should remain shared over the server's lifetime. I guess that on a heavily loaded system having to regularly reload your data will cost you more time and resources than looking-up the data in a database does.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: large perl module
by almut (Canon) on Mar 04, 2010 at 22:18 UTC | |
by minek (Novice) on Mar 04, 2010 at 22:27 UTC | |
by CountZero (Bishop) on Mar 05, 2010 at 07:05 UTC | |
Re^2: large perl module
by minek (Novice) on Mar 04, 2010 at 22:08 UTC | |
by almut (Canon) on Mar 04, 2010 at 22:32 UTC | |
by CountZero (Bishop) on Mar 05, 2010 at 06:53 UTC | |
by almut (Canon) on Mar 05, 2010 at 07:03 UTC |