lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Ok, I tried this, and on my "trivial" test case, even wrapping every
character in a Cmt, it not only avoids the excess memory usage, but
it's faster than "outside lpeg loop" case.

I then tried it on my real-world code, and it saves the memory usage
there too.

However, in that case, it's somewhat _slower_ than the "loop outside
lpeg" version, about 10% slower: 2m30s vs. 2m15s to parse about a
~700MB file.

For that grammar, the size of the individual clauses (the thing that's
looped) varies, but on average they're typical "programming language"
constructs.  Some clauses can be extremely large (but that shouldn't
matter, indeed large clauses should reduce the effect of any
per-clause overhead), but I think the majority are 3-400 characters in
length, with a reasonably complex grammar (lots of sub-rules and
sub-captures).

I find this a little surprising ... I'd think that even with lpeg.Cmt
around each clause, that wouldn't be any more expensive than
repeatedly calling lpeg.match for each clause instead...

Any clues as to why it's slower?

Thanks,

-miles

-- 
Faith, n. Belief without evidence in what is told by one who speaks without
knowledge, of things without parallel.