Skip to content

fix(stdlib): charge pattern matching to the budget and cap table element ranges - #447

Open
adriencohen wants to merge 2 commits into
deviceio:mainfrom
adriencohen:fix/stdlib-pattern-budget-and-element-caps
Open

adriencohen wants to merge 2 commits into
deviceio:mainfrom
adriencohen:fix/stdlib-pattern-budget-and-element-caps

Conversation

@adriencohen

Copy link
Copy Markdown

Stacked on #446: only the last commit is new.

Native stdlib work runs outside :max_instructions: a backtracking pattern runs for minutes, table.sort with a comparator is quadratic, and table.unpack accepts ranges of 10 million elements. Stdlib calls now draw on the instruction budget, and the element ceiling is a configurable option.

before after
string.find(("a"):rep(30), "a*a*a*a*a*a*a*a*a*a*b"), 10,000-instruction budget still running after 30 s refused in 30 ms
table.sort with a comparator, 4,000 shuffled elements 1.1 s, 4.0 M calls 23 ms, 43 k calls
same, 8,000 elements 4.0 s, 16.0 M calls 33 ms, 94 k calls

Before is #446. Apple M2, OTP 29.

The new :max_table_elements option defaults to 1,000,000 (PUC-Lua's stack limit), down from the fixed 10,000,000. table.sort with a comparator is now a merge sort, so the comparator is called in a different order. string.pack with a huge c<n> field, utf8.offset and greedy pattern scans still do their work before it is charged.

… depth limits

goto loops, __call chains, metamethod work and recursion that re-enters
Lua from native code (pcall, stdlib callbacks, Lua.call_function/3 from a
host callback) were not charged to :max_instructions or :max_call_depth,
so a script could loop or recurse without bound.
…ent ranges

Native stdlib work runs outside max_instructions: a backtracking pattern
runs for minutes, table.sort with a comparator is quadratic, and
table.unpack accepts ranges of 10 million elements. Stdlib calls now
draw on the instruction budget, and the element ceiling is a
configurable option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant