nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
41.25k stars 6.57k forks source link

Optimize binary `get_number` implementation by reading multiple bytes at once #4391

Open TianyiChen opened 3 weeks ago

TianyiChen commented 3 weeks ago

This PR improves performance for get_number implementation by reading multiple bytes at once, which saves calling overhead especially when interacting with file I/O. It adds get_elements to input adapters and allow them to select more efficient underlying calls to read multiple bytes if available

Performance for reading msgpack from C style FILE

develop

FromMsgpack/floats             166717521 ns    163715750 ns            4 bytes_per_second=52.4267Mi/s
FromMsgpack/signed_ints        171707844 ns    167527000 ns            4 bytes_per_second=51.234Mi/s
FromMsgpack/unsigned_ints      167388344 ns    164910750 ns            4 bytes_per_second=52.0468Mi/s
FromMsgpack/small_signed_ints  102578387 ns    100799000 ns            7 bytes_per_second=46.3689Mi/s

branch:

FromMsgpack/floats              61241576 ns     60370091 ns           11 bytes_per_second=142.174Mi/s
FromMsgpack/signed_ints         67659257 ns     62698083 ns           12 bytes_per_second=136.895Mi/s
FromMsgpack/unsigned_ints       59830260 ns     57518000 ns           13 bytes_per_second=149.224Mi/s
FromMsgpack/small_signed_ints   63264757 ns     61850167 ns           12 bytes_per_second=75.5688Mi/s

Questions:

Pull request checklist

Read the Contribution Guidelines for detailed information.

Please don't

github-actions[bot] commented 3 weeks ago

🔴 Amalgamation check failed! 🔴

The source code has not been amalgamated. @TianyiChen Please read and follow the Contribution Guidelines.

coveralls commented 3 weeks ago

Coverage Status

coverage: 99.951% (-0.05%) from 100.0% when pulling ea8b03d86452f42b8512144e6fd68020e9d7cd82 on TianyiChen:msgpack-int into 8c391e04fe4195d8be862c97f38cfe10e2a3472e on nlohmann:develop.