Skip to content

List.join is O(n²) due to repeated string concatenation #30

Description

@NightmarePog

The current implementation builds the result string by concatenating one element at a time in a loop. Since Lua strings are immutable, each `+` allocates a new string — so joining a list of n elements does n allocations of increasing size, which is O(n²) in total.

For small lists this is fine. For anything large it gets slow fast.

The fix is to collect elements into a Lua table and call `table.concat` at the end, which is what Lua itself recommends for this pattern. A `lua {}` body makes this easy to implement without touching the codegen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions