Replies: 4 comments 5 replies
-
That is indeed interesting, but I don't think it's actually reflective of real-world performance. The benchmark writes and reads once for each library a single YAML file with about 500 000 lines. That's obviously going to take a measurable amount of time and be different for different libraries, but is that really the size of file you're usually dealing with? If it is, is YAML really the right solution for you? In my experience, most real-world files are at most a few hundred lines long, and most real-world usage patterns have significant other work happening around the parsing that effectively makes the time spent figuring out what exactly the stream of bytes is meant to represent so marginal that even a 100x difference in the speed of that operation becomes effectively irrelevant. This isn't the case for all usages, of course, but I have not myself spent time explicitly benchmarking If there is a real-world operation where you find |
Beta Was this translation helpful? Give feedback.
-
For now I just found it interesting that two different libraries implementing the same quite complex specification to the last bit (as both pass all official YAML tests) can have quite opposite performance characteristics for reading and writing YAML. I also was a bit surprised that JSON is so much faster. Sure the much more complex syntax is responsible, maybe also the three-tiered processing stage (represent/construct, serialize/compose, present/parse) of YAML. I am currently starting using YAML files in a quite CPU constrained environment (an industrial controller with roughly the CPU power of a Raspberry 4). I don't know yet with how many YAML files the system will have to deal with, how big they will be and how often they will have to be read or written at the end, but performance is something I have to keep in mind. Maybe many of them can just be JSON files when there is no need for documentation resp. human editing or other features like type tags or aliasing. That said, maybe there are some low-hanging fruits for performance improvements. In my experience there always are :). |
Beta Was this translation helpful? Give feedback.
-
@ingydotnet : Thanks for the pointer! Very interesting. I was more looking for Javascript and .Net YAML libraries because I am responsible for the (React) UI, the NodeJS web service and a .Net backend, but this will maybe be helpful for my teammates who are responsible for the native C++ realtime part of our software. Wasm won't be helpful for me as the NodeJS web service will be the one dealing with YAML mostly, but maybe it can be used as a NAPI addon. |
Beta Was this translation helpful? Give feedback.
-
@gunters63 libfyaml compiles to wasm and runs fine with NodeJS. > cat libfyaml-wasm-test
set -ex
git clone -q https://github.com/pantoniou/libfyaml
cd libfyaml/
./bootstrap.sh &>/dev/null
emconfigure ./configure &>/dev/null
emmake make &>/dev/null
emcc src/tool/fy-tool.c -g3 -I src/valgrind -I include -L src/.libs -l fyaml -o fy-tool.js -s ALLOW_MEMORY_GROWTH=1 &>/dev/null
wget -q https://gist.githubusercontent.com/jeremychone/700b6ed721565e2488a2cff60b5ad749/raw/b827675c53f3838dd6097e42e6887e1f2b19474c/yaml-vs-json-perf.js
perl -p0i -e 's/router/{router}/' yaml-vs-json-perf.js
npm install cmdrouter fs-extra yamljs js-yaml &>/dev/null
node yaml-vs-json-perf.js write >/dev/null
: Native fy-tool
time fy-tool --mode json < data-yamljs.yaml > /dev/null
: WASM fy-tool
time node fy-tool --mode json < data-yamljs.yaml > /dev/null
: NPM yaml.js
time node -e 'console.log(JSON.stringify(require("yaml").parse(require("fs").readFileSync(0,"utf-8")),null,2))' < data-yamljs.yaml >/dev/null
> bash libfyaml-wasm-test
+ git clone -q https://github.com/pantoniou/libfyaml
+ cd libfyaml/
+ ./bootstrap.sh
+ emconfigure ./configure
+ emmake make
+ emcc src/tool/fy-tool.c -g3 -I src/valgrind -I include -L src/.libs -l fyaml -o fy-tool.js -s ALLOW_MEMORY_GROWTH=1
+ wget -q https://gist.githubusercontent.com/jeremychone/700b6ed721565e2488a2cff60b5ad749/raw/b827675c53f3838dd6097e42e6887e1f2b19474c/yaml-vs-json-perf.js
+ perl -p0i -e 's/router/{router}/' yaml-vs-json-perf.js
+ npm install cmdrouter fs-extra yamljs js-yaml
+ node yaml-vs-json-perf.js write
+ : Native fy-tool
+ fy-tool --mode json
real 0m1.918s
user 0m1.797s
sys 0m0.120s
+ : WASM fy-tool
+ node fy-tool --mode json
real 0m8.690s
user 0m9.211s
sys 0m0.421s
+ : NPM yaml.js
+ node -e 'console.log(JSON.stringify(require("yaml").parse(require("fs").readFileSync(0,"utf-8")),null,2))'
real 0m5.782s
user 0m9.984s
sys 0m0.544s |
Beta Was this translation helpful? Give feedback.
-
I ran a simple benchmark (used https://gist.github.com/jeremychone/700b6ed721565e2488a2cff60b5ad749 because I was lazy), these are the results:
Some interesting observations:
js-yaml is much quicker than yaml in reading, much slower in writing
yamljs@2 got much slower in reading than [email protected] (19 times slower than js-yaml!), performance is in the same ballpark with writing.
Beta Was this translation helpful? Give feedback.
All reactions