
JSON.encode writes a table with a number key as an array, padding every slot below that key with null. The time this takes grows with the square of the key, so a large key looks like a freeze: TTS stops responding and has to be force-quit.
Environment: TTS 2.0 public beta (Steam build 27134291, 2026-12-03); Unity 6000.7.0b9; Linux desktop; singleplayer host.
Reproduce (Global):
local t0 = os.clock()
local s = JSON.encode({[20000] = 1})
print(#s, os.clock() - t0) --> 100000 bytes, about 7 secondsMeasured, encoding a table with one entry:
| Key | Output | Time |
|---|---|---|
| 1 | 5 bytes | 0.1 ms |
| 49 | 245 bytes | 0.2 ms |
| 1000 | 5,000 bytes | 15.7 ms |
| 5000 | 25,000 bytes | 457 ms |
| 20000 | 100,000 bytes | 7.1 s |
How we hit it: JSON.encode(obj.getData()) on any card lying on the table. The card’s CustomDeck is keyed by its deck id (ours: 644533), so the encoder pads 644,532 nulls: about 2 hours and 3 MB of output at the rate above. The same card’s data taken from a deck’s getData().ContainedObjects encodes in 3.5 ms, because there its key was 49.
Expected: milliseconds, and a sparse table written as an object ({"644533": {...}}), as obj.getJSON() writes it.
Actual: the main thread is busy for hours building an array of nulls.
Workaround: obj.getJSON() returns the same card as JSON in 1 ms. For a mod’s own tables, use string keys.
Not checked: the current release (v14). The null padding may be long-standing; we can’t say whether the slowdown is new in 2.0.
Found while benchmarking a move of our card buttons to VisualUI.
