Skip to content

perf(vm): batch insert for :setlist instead of per-key Table.put #308

Closed

Description

@davydog187

Context

Table construction is 1.14× slower than luerl at n=100 (25.5µs vs 22.3µs
in benchmarks/table_ops.exs).

:setlist walks one key at a time through Table.put/3, paying the
seven-field %Table{} struct rebuild on every slot. Luerl's :array:set
amortises this to a single mutation.

Change

  • lib/lua/vm/dispatcher.ex:1412-1415 — set_list_into_table/6: accumulate
    {idx, val} pairs and call Table.replace_data/2 once at the end of the
    run instead of Table.put/3 per slot.
  • Mirror the change in the executor's :setlist handler (lib/lua/vm/executor.ex).

Helper Table.replace_data/2 already exists in lib/lua/vm/table.ex.

Verification

  • mix test (full suite stays green)
  • mix test test/lua/vm/stdlib/table_test.exs
  • mix run benchmarks/table_ops.exs

Expected

Closes most of the 1.14× build gap. Target: ≤ 1.05× luerl.

Activity

  1. added this to the 1.0.0 milestone on Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:perfPerformance change

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions