yaml-cpp icon indicating copy to clipboard operation
yaml-cpp copied to clipboard

load performance problem

Open Mack-y opened this issue 3 years ago • 2 comments
trafficstars

I have a yaml file which contains nearly 2000 nodes(4 or 5 map elements per node). At the very beginning, I intended to open it with file stream ,read every line of it and do some operations.
Then I found the yaml.cpp to load the file conveniently. But there is a performance problem:it takes more time when loading the yaml file using the yaml.cpp than directly open the file with stream and read every line of it.

I wanna do this paring job in the init phrase of a software,so my question is if there‘re some optimizations to do? Thanks!

Mack-y avatar Nov 23 '21 02:11 Mack-y

First, do you have metrics? Like, parsing the file takes N ms and you need it to take M ms? Second, filing a bug for "can you make this faster" isn't super useful; but, if you find a place that can be made faster, that could be more useful. For example, if you found a bottleneck that you have reason to think can be made faster, feel free to file a bug (and ideally, help fix it!).

On Mon, Nov 22, 2021 at 8:31 PM Mack-y @.***> wrote:

I have a yaml file which contains nearly 2000 nodes(4 or 5 map elements per node). At the very beginning, I intended to open it with file stream ,read every line of it and do some operations. Then I found the yaml.cpp to load the file conveniently. But there is a performance problem:it takes more time when loading the yaml file using the yaml.cpp than directly open the file with stream and read every line of it.

I wanna do this paring job in the init phrase of a software,so my question is if there‘re some optimizations to do? Thanks!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jbeder/yaml-cpp/issues/1067, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAICUBR5RZL5DINGB23MCUTUNL4ITANCNFSM5ISOEF6A .

jbeder avatar Nov 23 '21 04:11 jbeder

First, do you have metrics? Like, parsing the file takes N ms and you need it to take M ms? Second, filing a bug for "can you make this faster" isn't super useful; but, if you find a place that can be made faster, that could be more useful. For example, if you found a bottleneck that you have reason to think can be made faster, feel free to file a bug (and ideally, help fix it!). On Mon, Nov 22, 2021 at 8:31 PM Mack-y @.***> wrote: I have a yaml file which contains nearly 2000 nodes(4 or 5 map elements per node). At the very beginning, I intended to open it with file stream ,read every line of it and do some operations. Then I found the yaml.cpp to load the file conveniently. But there is a performance problem:it takes more time when loading the yaml file using the yaml.cpp than directly open the file with stream and read every line of it. I wanna do this paring job in the init phrase of a software,so my question is if there‘re some optimizations to do? Thanks! — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#1067>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAICUBR5RZL5DINGB23MCUTUNL4ITANCNFSM5ISOEF6A .

Thanks for your reply~ Sorry,I don't have metrics. Just because I found it takes more time when loading the yaml file by yaml.cpp than my unconveniently original method.

I made two simple demos to test the executing time like this:

1.yaml_load_time_test.cpp: `#include #include #include "../yaml-cpp-master/include/yaml-cpp/yaml.h"

using namespace std;

int main(int argc,char** argv) { YAML::Node config; try { config = YAML::LoadFile(argv[1]); } catch(const std::exception& e){ cout << "exception happen:" << e.what() << endl; return 0; } return 0; } ` time:0m0.853s

openfile_and_readEveryLine_time_test.cpp: `#include #include #include "../yaml-cpp-master/include/yaml-cpp/yaml.h" using namespace std;

int main(int argc,char** argv) { ifstream ifilePath; ifilePath.open(argv[1]); string lineString; while (getline(ifilePath, lineString)) {} return 0; } ` time:0m0.004s

If I used the lib the right way , I'm going to check the source code to find out which part or process takes the major time. But if you know the cause, please help me understand. Thks~

Mack-y avatar Nov 23 '21 07:11 Mack-y