Skip to content

Nontrivial string processing can get very slow #222

Open
@copumpkin

Description

@copumpkin

I think it's mostly caused the back-and-forth between lists of characters and strings.

For example, I have a function that takes a list of strings and "camelCases" the list, so that ["foo", "bar", "baz"] turns into "fooBarBaz". Using that function on lots of strings in my larger evaluation makes the whole thing take about 40s. Replacing it with a simple function (x) std.join("-", x) for hyphenated names reduces total evaluation time to 10s, keeping other things equal.

The camelcase code is as follows:

local upper(c): local cp = std.codepoint(c); if cp >= 97 && cp < 123 then std.char(cp - 32) else c;
local capitalize(str): util.upper(str[0]) + std.substr(str, 1, std.length(str) - 1);
local zipWithIndex(f, list): std.makeArray(std.length(list), function (i) f(i, list[i]));
local camelcase(list): std.join("", util.zipWithIndex(function (i, x) if i == 0 then x else util.capitalize(x), list));

Not the most beautiful thing ever, but it works as intended, other than being super slow.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions