On Thu, 6 Dec 2001, Garrett Goebel wrote:

> Maybe Sam Tregar could share some tips on do's and don't of speed
> considerations when writing a grammar. Lessons he's learned rewriting his
> grammar for HTML::Template::Expr.

Hmmmm, I don't know how general my observations are but here goes:

  1) Don't use autotree (duh).

  2) Rather than breaking out equivalent forms into separate rules combine
     them in a regex for a single rule.  Ultimately keeping the rule-count
     as low as possible seemed to help.

  3) Think carefully about the parse tree you want to build - if you don't
     need a particular piece of information then don't put it in the tree.
     I think this one was of particular importance for
     HTML::Template::Expr since it also allows the interpreter to be
     faster.

I worked in a strictly trial-and-error mode.  I'd make a change and then
run my benchmark.  If the time went down I kept the change, if not I'd
hurl curses into the sky and try again.

> I noticed this
> (http://search.cpan.org/doc/TBONE/Parse-RecDescent-FAQ-2.22/FAQ.tt)
> FAQ and thought you all might be interested. It has nice section
> called "OPTIMIZING YOUR GRAMMARS", and lots of other tips.

Interesting, I had no idea that existed!  Off to CPAN...

-sam

Reply via email to