Performance is very bad to build boost property tree from json file?

I use the boost property tree to load a jump file. However, performance is very poor.

For example, I have a json file 1.8M in size. A C ++ program for acceleration takes 3 seconds to load a json file and build a property tree. If I use python to load a json file, it only takes 0.1 second. And python will also build everything as an object.

A C ++ program is similar to:

int main(int argc, char **argv){ std::fstream fin; fin.open(argv[1], std::fstream::in); if (!fin.is_open()){ ASSERT(false); } boost::property_tree::ptree pt; try{ read_json(fin, pt); }catch(ptree_error & e) { ASSERT(false); } fin.close(); return 0; } 

A python script that does the same looks like this:

 #!/usr/bin//python import sys import json fp = open(sys.argv[1],"r") objs = json.load(fp) 

I tried the last impulse (1.54). It is still very slow.

Appreciate any advice.

If there is no solution, do you know any other C ++ library for loading / unloading json?

+4
source share
3 answers

It doesn't matter what is really in the JSON file. I tried several JSON files with different connectors. Boost is slow.

Now I have switched to jansson, which is much better - a quick and nice API to use.

0
source

I found that there is a huge difference between the Build Build vs Debug Build versions from VS for the property tree. on my specific hardware, parsing after 1 MB of the JSON file using read_json took 8 seconds in the Debug assembly, but only in version 0.7 sec.

+1
source

We had significant performance issues with boost :: property_tree and JSON. Our approach was to stop using std::string and use our own class of strings using a special allocator and hash table to not redistribute the same string twice. This has improved performance and memory usage by at least a few orders of magnitude for large JSON files.

Our JSON files were large enough for the std :: string distribution to occupy all available address space on a 32-bit machine. This approach will allow us to work with a margin.

+1
source

Source: https://habr.com/ru/post/1495691/


All Articles