Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've got a pretty large CGI::Application based application running under mod_perl. The application consists of several modules, but the "main" module is around 8000 lines. I am planning to refactor it into several smaller modules for the sake of maintainability, but I'm also wondering whether the size of the module has any performance impact. Thoughts?
  • Comment on Does module size matter under mod_perl?

Replies are listed 'Best First'.
Re: Does module size matter under mod_perl?
by davido (Cardinal) on Jul 06, 2014 at 07:12 UTC

    Does module size matter under mod_perl?

    Assuming you have sufficient memory to stay out of swap, no, module size doesn't have any direct relationship with performance.

    There are typically two performance considerations with languages such as Perl. Upon startup, Perl code is compiled to bytecode and then interpreted and executed. Loosely speaking there is a compiletime stage, and a runtime stage. The first consideration is compile time. This can be an issue for applications that start up frequently such as plain old CGI. And for such applications, minimizing start-up time by sticking to lightweight, concise modules has some benefit. But it is not relevant to a mod_perl application because start-up happens only once in awhile.

    The other performance consideration is runtime performance. There is no direct correlation between a module's size and its runtime performance.

    So go ahead and re-factor if it makes sense to do so for some other reason such as project scalability, simplification of maintenance, or improved modularity / code-reuse. Just don't expect for it to have any effect on runtime efficiency, unless algorithms are improved in the process.


    Dave

Re: Does module size matter under mod_perl?
by thomas895 (Deacon) on Jul 05, 2014 at 21:06 UTC

    The size of the module isn't nearly as important as what it does.
    For example, one could do incredibly complex calculations in just a few lines of code and have that take several seconds to execute.
    On the other hand, in several thousand lines one could also write a blog that only does some simple text processing and manipulation, which would be very fast.
    Of course, the modules you load can have an impact. POSIX is notorious for being very large. Loading this would probably lead to an increased memory usage.

    The best thing to do is to try it. There are dozens of articles online about stress-testing one's website.
    Then, refactor as you said, and try it again. Fix whatever, if anything, is slow. Then try it again.

    ~Thomas~ 
    "Excuse me for butting in, but I'm interrupt-driven..."
      Yup, that POSIX with its 2mb increase ...how large :)
Re: Does module size matter under mod_perl?
by dsheroh (Monsignor) on Jul 05, 2014 at 19:20 UTC
    In principle, yes, module size does have some marginal impact on performance, if only due to affecting the amount of time it takes to read the file from disk.

    In practice, if the amount of difference it makes is significant to your application, then Perl is the wrong language for you to write that application in. You'll get much bigger gains by switching to a higher-performance language than you will by worrying about module sizes in Perl.

      In mod_perl, you'd load the module once when the web server is loaded. How long it takes to load is completely unimportant.
        Yes, the difference is completely unimportant, if there's even a measurable difference at all. Which was my point.