Skip to content

fix(vm): decode shared tables once and cap the decoded size - #445

Open
adriencohen wants to merge 1 commit into
deviceio:mainfrom
adriencohen:fix/decode-shared-tables-once
Open

adriencohen wants to merge 1 commit into
deviceio:mainfrom
adriencohen:fix/decode-shared-tables-once

Conversation

@adriencohen

@adriencohen adriencohen commented Nov 27, 2026 •

Copy link
Copy Markdown

A few tables that reference each other expand exponentially when decoded to Elixir, after the script has finished and out of reach of :max_instructions.

t = {t, t} repeated before after
18 times 180 ms 42 µs
20 times 480 ms 42 µs
22 times 2.4 s refused in 58 µs

Lua.eval!/2 including decode, median of 5 runs (1 run past a second), Apple M2, OTP 29.

Each table is now decoded once and its term reused wherever it appears. A new :max_decode_nodes option (default 5,000,000) caps the expanded size, counting a shared table once per place it appears, and raises Lua.RuntimeException past it. With decode: false the display snapshot is marked :truncated instead. A table on a reference cycle reached by several paths now decodes to the same term each time.

A few tables that reference each other expand exponentially when decoded
to Elixir, after the VM has finished and out of reach of
max_instructions. Each table is now decoded once, and a new
max_decode_nodes option (default 5,000,000) caps the result.
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