title: Runtime script evaluation in Grails - Best Practicse
body: <p>In our application, numerous emails are being sent from the system. These emails were of the same format for all users with different contextual variables populating the dynamic data.</p>
  
  <p>We are now planning a feature to allow administrators to edit and customize these templates. As such the plan is to use the groovy shell to evaluate the templates at run time e.g.</p>
  
  <pre><code>Binding binding = new Binding();
  binding.setVariable("model", [var1: "First Name", var2: "Last Name"])
  GroovyShell shell = new GroovyShell(binding);
  
  Object email = shell.evaluate('return "&lt;html&gt;&lt;title&gt;Test Shell&lt;/title&gt;&lt;body&gt;${model.var1} ${model.var2}&lt;/body&gt;&lt;/html&gt;";');
  </code></pre>
  
  <p>This seems to work adequately for us. The questions I have are:</p>
  
  <ol>
  <li>Is the GroovyShell the preferred engine to use or is Rhino or other better?</li>
  <li>Are there any performance concerns or memory issues to be aware of? Any low hanging fruit we can optimize i.e. can the shell or binding be reused</li>
  <li>What's the biggest bottleneck in the above code? The construction? The evaluation?</li>
  </ol>
  
  <p>thanks</p>