Designer freeze and possible memory leak caused by large number of JSON errors

I have a couple relatively large dicts stored in my session custom properties. These are initialized once using a binding (and sporadically refreshed) so that I can cache them for the rest of the session. While these dicts are valid in Python they aren't valid JSON, so despite being fully functional they will raise an absurd number of JSON warnings in the Perspective property editor. For example, here is some nonsense data with the same format and a similar size:

Generation script
import random
from string import ascii_letters as letters, digits
digitStr = lambda d: "".join(random.choice(digits) for i in range(d))
randomString = lambda: random.choice(letters) + '.' + digitStr(2) + '.' + digitStr(7) + '.' + digitStr(2)
return {randomString(): [i, i*2, i*3] for i in range(5000)}

This implementation works fine but has several side effects in the Designer:

  • The Perspective configuration menu (not sure what this is called - the one that appears when you click on the main Perspective node in the Project Browser) becomes sluggish to open. Opening (or attempting to open) this page locks up the Designer for several seconds, and even more with larger dicts (several minutes when I changed the script above to return 50,000 keys instead of 5,000).
  • Clicking on the warning count locks up the entire Designer for a really long time, usually a minute or more with 5,000 keys.
  • It seems to be causing a memory leak in the designer (although I don't have a way of double checking this).

I could replace the periods with underscores or some other similar workaround but I am comparing the key names in this dict in other places, meaning I'll have to string-replace several times which feels computationally wasteful - but again, it works completely fine the way it is aside from the Designer. Regardless it's something I have bumped into a few times on this project alone and it's been just as frustrating every time :frowning_with_open_mouth:

You simply can't expect to use invalid JSON in Perspective properties. :man_shrugging:

Consider using my toolkit's sessionVarMap() or pageVarMap() to hold true jython/java objects without this freakout. Note that you can use expressions that extract from jython dicts stored within VarMaps without downside, as long as the final value assigned to a Perspective property is itself valid.

2 Likes