Skip to content

perf(stdlib): parse string.format flags into bitmask, integer specifier #309

Closed

Description

@davydog187

Context

string.format per-specifier paths re-scan the flags binary with
String.contains? on every specifier site, and dispatch on the conversion
character as a one-byte binary (e.g. \"d\") rather than an integer (e.g.
?d). Luerl precomputes a bitmask and dispatches on \$d
(deps/luerl/src/luerl_lib_string_format.erl:72-156), which is faster under
BEAM pattern matching.

Change

lib/lua/vm/stdlib/string.ex — apply_format_spec/2 at line 413 and the
parser that produces {flags, width, precision, specifier} tuples.

  • Parse flags into a small tuple of booleans (or single integer mask)
    once at parse time.
  • Store the conversion char as ?d/?f/… (integer) rather than a binary.

Pure internal refactor — observable output unchanged.

Verification

  • mix test test/lua/vm/stdlib/string_test.exs
  • Full mix test
  • mix run benchmarks/string_format.exs

Expected

~10 % of the spec-heavy gap. Stack with T4/T5 for the full close.

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