in reply to Cost of passing function references
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Cost of passing function references
by choroba (Cardinal) on Sep 17, 2015 at 15:21 UTC | |
|
Re^2: Cost of passing function references
by Anonymous Monk on Sep 17, 2015 at 20:59 UTC |