There's next to no decision making (failed key backtracks to '}', failed record backtracks to /\Z/), so it shouldn't be intrinsicly slow. Rules like a : b c | b d could easily drag down the parser, but there's no such rule.

The parser might be copying the entire unparsed input text everytime it calls a rule, instead of just keeping a pointer to the current location within the text. This could lead to high memory usage and swapping.

The parser provides a number of variables to each rule. Some provide info to error-reporting functions, even if they are not used. Some are to allow actions to be as flexible as possible. There could be lots of overhead. Reducing the number of rules by inling those without '|'s should speed things up, but would have an severe impact on readability and maintainability.

You could try turning off warnings. I have no idea how much overhead they add.

Instead of returning a data structure, the actions could add to a data structure as soon as a rule is parsed. This could save a lot of memory and copying.

You could Precompile the grammar and look at it. Or even use it as if it was Precompiled:

Parse::RecDescent->Precompile($grammar, 'g') or die("Bad grammar\n"); require g; my $p = g->new(); my $text = ...; my $data = $p->parse($text) or die("Bad data\n");

In reply to Re^6: Pulling data out of { } by ikegami
in thread Pulling data out of { } by Felix2000

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.