sometimes match or gmatch are very slow under luajit (compared to raw lua)

  • From: Ronan Collobert <ronan@xxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 18 Sep 2012 14:00:55 +0200


Under certain conditions that I am unable to determine, string.match or 
string.gmatch are very slow on luajit, compared to raw lua (x10 or even x25 

It seems not to be related to the match pattern: a simple gmatch('(.-)\n') to 
get the number of lines of the file might already a concern.

I try to generate random files where this would happen, with no success: I 
really can't find the "trigger" which makes the thing (match or gmatch) slow.
In attachment I provide a small example (tar-gz archive) where I do get this 
slowdown, both on my Mac OS 10.6 (i7 2.8Ghz) or on my Ubuntu 10.04.4 LTS (i7 
3.07 Ghz):

time luajit test.lua 
real    0m1.107s
user    0m1.100s
sys     0m0.000s

time lua test.lua 
real    0m0.151s
user    0m0.130s
sys     0m0.020s

I am using the last luaJIT from the luajit-2.0 git master branch, as well as 
lua 5.1.4.

Any idea?

I noticed someone posted a somewhat related problem previously: 


Other related posts: