Everyone,

Thanks a bunch for very helpful responses. After talking to the reviewer, it turned out that he was thinking along the lines of adding one more layer of "eval" in the code. The line of thought was something like this (I may not be capturing it correctly):

1. Perl interpretes (compiles?) the code as it sees it. I am not sure at this point if perl creates an executable or a bytecode of the module. The reviewer thinks that the interpreted code is just one big buffer of string.

2. If a function is used as is, the function name exists in the buffer. In that case, executing the code would involve just looking up the function by its name in the process memory space and executing it.

3. If a reference is used, the interpreted string buffer needs to be "reinterpreted" (or recompiled?) by substituting the function name in place of the reference. Since perl does not have an executable, each time the CGI comes in from the backend, this process is repeated for the module, which can add a significant overhead to the server side execution. Since I am changing a core library which will eventually lie in the path of our entire UI, the UI can get slower. Even a 5% slowdown would be very annoying.

I agree that I do not know perl. A bit embarrassed actually, because I have no clue how the perl code is executed. I read in the responses that perl code is compiled, but I don't know what's the result of that compilation. Is the compiled code loaded in memory (if I read one of the responses correctly, looks like it is loaded in some kind of "glob" structure?) and then executed? What happens if there is thousands of lines of code in a perl module? Is everything loaded in memory? Will that cause some memory issues?

We mutually agreed that for now, we do not need the pattern, and since I had to call a couple of DBI functions only, it was better to wrap those 2 functions separately in the try-catch-throw pattern and call the wrappers instead. If the number of functions we need to call in that way start to increase, we will revisit the pattern.

I would appreciate more insights on perl code execution and good resources I can look into. Again, thanks a bunch for all the help!


In reply to Re: Cost of passing function references by sportsfan33
in thread Cost of passing function references by sportsfan33

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.