-
Notifications
You must be signed in to change notification settings - Fork 5
Excessive use of JSON stringification in PTree file format #106
Description
By looking into a .ptree file with a text editor, I noticed - cf #98 (comment) - that PTree doesn't dump a JSON representation of its complete object hierarchy, but rather nests JSON string representations at each hierarchical level (resulting in massive amounts of quote escaping).
Thus the beginning of a .ptree file looks like this: {"tree":"{\"item_list\":[\"{\\\"id\\\":0,\\\"type\\\":\\\"root\\\".... This not only really feels wrong and inflates the file size, it also impairs the interoperability of PTree by making it much more painful to write software that would parse the contents of a .ptree file.
The culprit is the use of JSON string-ification at several steps of its internal object structure saving/loading system. Internally, the entire code base should manipulate hierarchies of plain JS Objects and only ever make use of JSON.stringify / JSON.parse at a single point: when writing/reading the structure into/from a file on disk.
Unnecessary round trips through the JSON formatter/parser are also used internally for most IPC requests (sending data to/from popup windows) which are perfectly able to work with JS object hierarchies as arguments.
I know changing this isn't much fun, so I'm only creating this issue now because I've spent some time working on it seriously :)
(I still have to implement read compatibility with the previous format, though, so the PR's not ready yet)