lua-users home
lua-l archive

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


Hi,

Roberto Ierusalimschy wrote:
> I have released a new version of LPeg (0.5). The main changes are
> several optimizations, which should make LPeg much faster for several
> common tasks.

It seems to be ~30% faster than LPeg 0.4 in my tests. Pure
matching is now on-par or slightly better than string.match.

But extensive substitutions are still ~60% slower than
string.gsub. I think this is due to the large intermediate
structures which cause more D-cache misses.

> (On the other hand, these optimizations make patterns
> less regular, and therefore more difficult to test...)

Well, the optimizations sure look tricky (but I haven't found any
flaw in the logic). :-)

I would have picked the low-hanging fruit first:
- Remove the s<e test from IChar for non-NUL chars
  and add ICharZ which checks for s<e and NUL.
- Merge 2 or 4 successive IChars to IChar2 and IChar4.
- Let IAny check for more than one char.

Also, looking at the machine code, for some reason GCC is unable
to keep p and s in registers. Probably some lifetime leak or
maybe the control-flow is too complex? Fixing this should improve
performance a lot.

Bye,
     Mike