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

I have a vague suspicion that they might be avoiding imports due to the memory cost - which is significant in a mod_perl environment.

Importing is aliasing. You're not copying the function, but merely aliasing it. All it costs is one symbol table entry.

Things are different when autoloading takes place, but it depends on the implementation then.

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

  • Comment on Re: Re^2: Pragma (more) like Java's 'import'? (importing and mod_perl)

Replies are listed 'Best First'.
Re: Re: Re^2: Pragma (more) like Java's 'import'? (importing and mod_perl)
by perrin (Chancellor) on May 12, 2003 at 06:49 UTC
    The aliasing uses memory, and it can really add up in a persistent environment like mod_perl. See this for more specifics.

      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.