lua-users home
lua-l archive

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


Hi !

After I've upgraded Lua to 5.3.2, one of my scripts terminates with
"pattern too complex" error message.

Probably, this is because of gmatch using non-optimal pattern
(having quadratic time complexity), which may require up to 2 sec
to complete.

Of course, it is possible to rewrite that script to make its time
complexity linear (at the cost of extra LOC and more complex logic
of code).

But the are two reasons for NOT rewriting it:
1) I don't want to spent my time on rewriting my old script
because I'm quite happy with its current performance (2-3 seconds
is OK for me).
2) I don't want to bring extra complexity to the script.
As for now, it is one-liner regexp, and I'd like to stay it
as simple as it is.

Frankly speaking, I'd like to see time constraint be removed from
pattern functions, as it unpleasantly reduces their abilities.
Currently I've rolled back to previous Lua version to solve
my problem, but I want to know how to invoke Lua pattern functions
providing unlimited execution time for them?

Is there more convenient way than rebuilding Lua with modified B_REPS
in lstrlib.c?
Can I set B_REPS using -D compiler switch to keep the sources intact?

Of course, in some situations it may be very useful to apply time
constraint on some Lua code (especially code containing pattern
functions, "while" loops, recursion, etc.)
IMO, more correct way to achieve this is to introduce new function
time_restricted_pcall(max_CPU_time, func, args)
instead of hard-coding such limitations.

-- Egor