Skip to content

[Bug]: setTableEntry extremely slow #4769

@Azhrei

Description

@Azhrei

Describe the Bug

When adding 3200 elements to a new table using setTableEntry(), MT can consume significant cpu and even more memory (upwards of 48GB!).

To Reproduce

Execute the follow macro and note the execution time. Then comment out or delete the setTableEntry() and run it again.

[h: pattern = "Dex"]
[h: replaceWith = "DEX"]
[h: tableName = "Beasts"]
[h: stringIndex = "40"]

[h, COUNT(3200), CODE:
    {
        [h: stringList = table(tableName, roll.count)]
        [h: value = listGet(stringList, stringIndex, "~")]
        [h: value = replace(value, pattern, replaceWith)]
        [h: stringList = listReplace(stringList, stringIndex, value, "~")]
        [h: setTableEntry(tableName, roll.count, stringList)]            
    }
]

Expected Behaviour

The setTableEntry() function should overwrite an existing entry if it's there, or add a new one if it isn't. (The latter is new functionality that doesn't exist in the current version, so the wiki will need to be updated.) Unfortunately, I don't see a way to change the return code so that it can indicate whether an entry was added or replaced and still maintain backward compatibility.

Screenshots

No response

MapTool Info

All

Desktop

Any

Additional Context

See this Discord discussion for the initial report from Full Bleed.

Metadata

Metadata

Labels

bugclaimedIssue is being actively worked on.documentation neededMissing, out-of-date or bad documentationfeatureAdding functionality that adds valuemacro changesThis issue adds or changes macro functions. Extra work is required (testing, wiki, code editor)performanceA performance or quality of life improvementrefactorRefactoring the code for optimal awesomeness.

Type

No type

Projects

Status

Merged

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions