openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.98k stars 2.55k forks source link

Reducing bloated output from ofxXmlSettings (suggestions) #3057

Open golanlevin opened 10 years ago

golanlevin commented 10 years ago

I realize it's dumb to complain about XML being bloated ("then don't use it!) but:

There are some simple things we could add to reduce the bloating of output produced by ofxXmlSettings, particularly for large files.

The first is to allow floatPrecision in ofxXmlSettings.cpp to be user-adjusted. There are times when I really don't need to know fractions. out to 9 places. This could be another argument passed in to XML.setValue(), or it could be a global variable that's adjusted by the user.

Likewise, I don't see why tinyxml.cpp hardcodes four spaces for indents. I'd like the option of using tabs, or an adjustable number of spaces. There are a number of functions called Print in tinyxml.cpp that would need to be changed: fprintf( cfile, " " ); which could optionally be replaced with tabs, i.e. fprintf( cfile, "\t" );

Testing would need to be done to ensure that the files could still be read, of course.

These changes would allow a very large reduction in file size, without compromising the value of the XML output.

kylemcdonald commented 10 years ago

these seem fairly noncontroversial changes, if someone tackles this via PR i'm sure it would be accepted quickly if the commits are clean.

that said, large XML files are not the primary use case of ofxXmlSettings, using json or yaml or another serialization lib might work better.

bakercp commented 10 years ago

To further Kyle's thoughts, for XML I'd recommend looking into Poco::XML (which is wrapped by ofXML and has some basic xpath capabilities) [http://pocoproject.org/slides/170-XML.pdf] or pugixml (used in project generator for its xpath capabilities -- I just uploaded a quick addon wrapper here https://github.com/bakercp/ofxPugiXML). Higa's https://github.com/satoruhiga/ofxYAML or https://github.com/bakercp/ofxJSON might also be useful.

Additionally the base classes for serialization using ofXML etc are already in the ofCore and used in ofxGui (http://www.openframeworks.cc/doxygen/classof_base_serializer.html).

jsoncpp (which is underneath ofxJSON) removes spaces during serialization unless you write it with "pretty print" turned on.

If you really want to compress things down, you might look into protocol buffers (https://developers.google.com/protocol-buffers/docs/cpptutorial - also Paul demonstrates them here https://github.com/paulreimer/ofxWebUI) or msgpack (https://github.com/msgpack/msgpack-c).

Anyway, all that said the changes to tinyxml should be fairly straight forward. :)

bilderbuchi commented 10 years ago

pinging @joshuajnoble as he previously worked on OF&xml.

joshuajnoble commented 10 years ago

I'd agree with this and, as Kyle points out, it seems quite non-controversial. I'm not super-familiar with the internals of ofxXmlSettings but I'd be happy to make this a bit lighter. This also seems like something that I'd mirror in ofXml as well.