in reply to Re: Re^2: Pragma (more) like Java's 'import'? (importing and mod_perl)
in thread Pragma (more) like Java's 'import'?

The aliasing uses memory, and it can really add up in a persistent environment like mod_perl. See this for more specifics.
  • Comment on Re: Re: Re^2: Pragma (more) like Java's 'import'? (importing and mod_perl)

Replies are listed 'Best First'.
Re: Re: Re: Re^2: Pragma (more) like Java's 'import'? (importing and mod_perl)
by Juerd (Abbot) on May 12, 2003 at 07:28 UTC

    See this for more specifics.

    6 MB is not much. If it were 6 MB per process, it would be a problem, but it is 6 MB for 30 (!) processes, so that is 0.2 MB per process. If you can't live with that, you should probably use C, not Perl. 6 MB of RAM costs approximately US$ 0.85. Compare that to time spent on fully qualifying symbols in distant packages.

    Besides that, CGI.pm exports an excessive amount of symbols (158 for :standard).

    And I really do not understand why people who care about efficiency this much, using micro optimizations all over the place, use functions to generate HTML (or if they don't, why they import a bunch of symbols that they never use). As if optrees don't use memory. As if calling a function has no runtime overhead.

    To all CGI.pm users out there: if you care about memory usage and run speed, don't use CGI.pm. Don't waste your time by doing silly benchmarks and calculations that focus on a mere 20 kB per script per process while CGI.pm itself uses 950 kB (of which not everything stays shared), and you have runtime function call overhead for HTML tags.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

      It's all relative. CGI.pm is an extreme example, but importing many functions from different modules could have a similar effect. 6MB less RAM available might mean that you have to run 3 fewer apache processes.

      The important thing to get from this is that importing can add up in a persistent multi-process environment, and it should be used wisely.

        6MB less RAM available might mean that you have to run 3 fewer apache processes.

        Even then. That assumes 2 MB of unshared memory per process. Suppose a bare server with Apache's parent process uses 128 MB and you have 1024 MB installed, which is not uncommon for modern x86 based servers. Still enough memory to run 448 apache processes. If your CPU and I/O (filesystem/disk mostly) can handle that amount of requests simultaneously, you should have bought more than 1 GB of RAM, since 1 GB is not at all much for systems like that.

        The important thing to get from this is that importing can add up in a persistent multi-process environment, and it should be used wisely.

        Importing should be done wisely, but it should not be avoided. If you explicitly request only the symbols that you use, it's always worth it. If you use all of the 158 symbols that CGI.pm's :standard tag exports, then by all means have it export them, because the overhead of importing is nothing compared to the overhead of using them, and typing "CGI::" 158 or more times *will* drive you crazy :)

        Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }