Skip to content

perf(vm): split-storage tables (Erlang :array + map) #314

Closed

Description

@davydog187

Context

Structural follow-up after Tiers 1–3 (issues T1–T7). Only worth pursuing if
table-build / sort residual gap persists after the per-element write-back
fixes (T1, T2) — otherwise defer or close.

We currently store array and hash keys in a single %Table{} map plus an
order/order_tail/dead triple (lib/lua/vm/table.ex). Luerl
(deps/luerl/src/luerl_heap.erl:127-281) routes integer keys ≥ 1 to
Erlang's :array module (dense, O(1) functional update) and other keys to
a tree dict.

Splitting storage is the deepest structural lever for going past luerl
on table-heavy workloads.

Change (sketch — requires its own design pass first)

  • lib/lua/vm/table.ex — %Table{} becomes {array, hash, meta, ...}.
  • Update every read/write/iter site:
    • lib/lua/vm/stdlib/table.ex (sort, insert, remove, concat, pack/unpack)
    • Executor :get_table / :set_table / :newtable / :setlist /
      :get_table_n / :set_table_n handlers in lib/lua/vm/executor.ex
    • Dispatcher equivalents in lib/lua/vm/dispatcher.ex
  • Rework length, pairs, ipairs. Order tracking can simplify — :array
    gives dense-integer ordering for free.

Process

Frame as a research spike first. Land a prototype on a branch, benchmark
in isolation, decide whether to merge based on measured gain vs the
refactor cost.

Verification

  • mix test (full suite)
  • Lua 5.3 official suite
  • All benchmarks/* runs — no regressions, gains where expected

Expected

Pushes us ahead of luerl on table-build / sort. Closes the array-iteration
gap at larger n. Possibly closes the state.tables Map.fetch cost too.

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