Pattern-Script icon indicating copy to clipboard operation
Pattern-Script copied to clipboard

Editor lags/stops when expending too many tags

Open ClementSparrow opened this issue 3 years ago • 2 comments

The following code makes the editor lag on my computer (1-2s reaction time):


ID = D0 D1 D3 D3 D4
B = T F

========
OBJECTS
========

Crate:ID:B:B:B:B:B
white

Adding a :B makes it stops totally. It's likely that the parser code takes too much time to process the expansion.

I probably can't do anything about that except optimizing but the issue will always exist unless I put hard limits. A better approach would be to detect the lag and raise an error if there are too many tags to expand, explaining that the user should expand manually the remaining tags.

ClementSparrow avatar May 15 '22 13:05 ClementSparrow

Since commit b4764655f299e689adaf1f888da7fa248a0d668f, sprite transformations are not performed during parsing and this should alleviate this issue in general, but has no impact on the example provided in this issue.

ClementSparrow avatar Aug 08 '22 13:08 ClementSparrow

Each tag added to an object name multiplies by N+1 the number of objects generated, where N is the number of tags in the tag class used. So in the example in this issue, Crate:ID:B:B:B:B:B would create 6x3x3x3x3x3 = 1458 objects. It is not that much, but the way CodeMirror works is by creating many copies of the parsing state, including the list of all identifiers defined, so copying the state takes a time proportional to the number of objects defined. Also, every identifier check performs a linear search for the object name in the list of all objects, so there might be a huge speed boost if we simply use hash tables instead. Or maybe, searching for objects tag by tag.

ClementSparrow avatar Aug 08 '22 13:08 ClementSparrow