Re: Efficient string parsing

  • From: Mike Pall <mike-1210@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 24 Oct 2012 11:41:11 +0200

Wolfgang Pupp wrote:
> I'd be very thankful for any input- I am not too familiar with parser
> design in general, and all the information I found only suggested to
> not use string functions/concatenation since it prevents JIT
> compilation, but no alternatives...

The first instinct would be to try pattern substitution until it
matches valid Lua code and then simply pass it to the Lua parser.

OTOH it's not easy to write a parser in Lua by hand *and* still
get good performance. Going through an uint8_t[] with a position
index and making decisions based on the retrieved bytes is
probably the fastest way. You'll have to sort conditionals by
frequency, do some tricks like scanning a few more bytes at once
(append a sentinel at the end), try branchless approaches etc.
More or less the things you'd do in plain C, too.

--Mike

Other related posts: