Greatings,
I have set of Data as an Dict/Array. I would like to use it at several points in my script and right now I
have defined a StringProperty and stored the JSONified Array into it. And when I need it, I grab the StringProperty´s text… transform it into a dict and use the data.
This works fine!
However, I just think: Is this the way?
What are the Pro´s and Con`s ?
Pro:
Multidimensional, easy to write data
Con:
Decode to acces data…
Any thoughts? Seuggestions? Warnings?
How much text can I even save into a StringProperty?
Depends on the data. It could be that storing on disk as a csv makes development easier because you can edit the data in a spreadsheet without needing to make every little change in code.
Or if you use properties on datablocks, you can store the data as a dict directly.
I don’t know what this means. The attributes used in a draw loop or user editable properties?
Why do you need to store this information outside of script code in the first place?
Well it is not the way Blender’s devs designed data serialization to be used, but on the other hand it is pretty much why json was invented. In these cases I’d just go with a saying : “If it works, it works”. Don’t overdesign. If you’re okay performance wise to json.loads and json.dumps every time you read and write the data, then go for it. AFAIK you can store arbitrary lengths of data in a StringProperty.
If you want to make the system hyper robust and usable in other parts of your addon without a sweat, you’ll have to spend some time designing an elaborate system of PropertyGroup and CollectionProperty, time you won’t spend on other parts of your addon.
Or you can store the properties on disk, but this also has a few problems of its own, like OS specific restrictions etc.
Just for reference the entire source code of this HTML page is about 790.000 characters and some 780KB on the disk. This is quite good amount of string and a reasonable size to store and maintain in memory. But after 1MB or 5MB things get almost unoptimal.
In this case saving/loading from disk is far more reasonable.
It depends on the tests, perhaps you can try StringPropery first and then if you actually see that is not optimal solution then saving to disk wins.
A cool story: Some legendary programmer managed to improve GTA loading times by 70%. Though the technical details of the C++ implementation is not of this subject.
A 10MB JSON file is very sus… Perhaps it shouldn’t exist at all like that. In these cases the best solution is sqlite.