Note that there are some explanatory texts on larger screens.

plurals
  1. POFaster alternative to eval?
    text
    copied!<p>I'm dealing with a web app that uses a home-grown templating system that lets Perl code be embedded in HTML. These statements are executed by the template parser at run-time using <code>eval EXPR</code>.</p> <p>This is very flexible, but these statements are scattered everywhere, and get executed a <em>lot</em>. <code>eval EXPR</code> (as opposed to <code>eval BLOCK</code>) requires Perl to fire up the interpreter each time, and my profiling reveals that they're a reasonably significant source of slowdown.</p> <p>Many of the embedded Perl statements are very simple. For example, a template might have a line like this:</p> <pre><code>&lt;p&gt;Welcome, &lt;!--E: $user-&gt;query('name') --&gt;. </code></pre> <p>Or:</p> <pre><code>&lt;p&gt;Ticket number &lt;!--E: $user-&gt;generate_ticket_number() --&gt; has been generated. </code></pre> <p>That is, they're just calling object methods. There are more complicated ones, too, though.</p> <p>I'm hoping to optimize this, and so far have two ideas, both of which are terrible. The first is to rewrite all templates to replace simple calls with tokens like <code>USER:NAME</code> and <code>USER:GENERATETICKETNUMBER</code>, which the parser could then scan for and invoke the appropriate object method. But then instead of dealing with templates that mix HTML and Perl, I would have templates that mix HTML, Perl, and tokens.</p> <p>The second idea is to try to parse the embedded Perl, figure out what the statement wants to do, and, if it's simple enough, call the appropriate object method via a symbolic reference. This is obviously insane.</p> <p>Is there some logical solution I'm overlooking?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload