Skip to content

stdlib hot paths: string.format iolist + plain-table fast paths (B9) #273

Closed

Description

@davydog187

Tracked by plan: .agents/plans/B9-stdlib-hot-paths.md

The plan file is the source of truth for goal, scope, success criteria, and implementation notes. Comments here are for discussion; the plan is for execution.

Why now

Benchmark gaps that aren't dispatcher-shaped:

  • string.format is 1.77x slower than Luerl and 5.5x slower than C Lua. lib/lua/vm/stdlib/string.ex:333-350 builds the result by per-character binary concatenation (acc <> <<char>>), which reallocates on every literal byte. Iolist accumulation + a single IO.iodata_to_binary/1 at the end closes most of this gap.
  • table.sort is 1.76x slower than Luerl. lib/lua/vm/stdlib/table.ex:249-288 routes every read through Executor.table_index/3 and every write through Executor.table_newindex/3, even for plain integer-indexed tables with no metatable. A table.metatable == nil fast path skips ~200 Map.fetch! + branch checks per 100-element sort.
  • table.concat has the same per-slot Executor.table_index/3 overhead pattern.
  • apply_width_flags uses String.length (O(graphemes)) when byte_size would do — format output is by definition single-byte for %d/%f.

These are stdlib-side fixes, independent of dispatcher coverage. Wins stack with #271 and #272.

Out of scope

  • The O(n²) insertion sort path when a user-supplied Lua comparator is passed. Latent issue worth fixing but no current benchmark exercises it; defer until a comparator workload motivates it.
  • Table.put's order_tail allocation on every write. Defer; profile after Dispatcher: cover table opcodes and :numeric_for (B5b-v2) #271 lands to see if it's still the ceiling.

When this work is picked up

  1. The branch named in the plan's frontmatter is created.
  2. A PR is opened with Closes #<this-issue> in the body.
  3. Merge closes this issue.

For strategic context, see ROADMAP.md.

Activity

  1. added this to the 1.0.0 milestone on May 28, 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

    direction:BDirection B: performance investigationkind:perfPerformance change

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions