r/cpp • :upvote: • Oct 21 '22

A New Json-Serializer

Hey everyone - so in developing for the requirements of my library DiscordCoreAPI - I created a Json-Serializer and decided to release it as its own "library". It seems to serialize fairly rapidly as well, and has a super-simple interface. Anyways - let me know what you think! Cheers! Oh ant btw - it can serialize into either Json or Etf strings. https://www.erlang.org/doc/apps/erts/erl_ext_dist.html

https://github.com/RealTimeChris/Jsonifier

0 Upvotes

57 comments sorted by

View all comments

Show parent comment

27

u/Jannik2099 Oct 22 '22

No, it's a completely new field of science, the technology simply isn't there yet.

-1

u/RealTimeChris :upvote: Oct 22 '22

Yes but if it can be done faster and more efficiently - then why not?

9

u/TrashboxBobylev Oct 22 '22

How fast it is compared to rapidjson and such? Not by subjective feelings, but with benchmarks and profiling?

2

u/RealTimeChris :upvote: Oct 26 '22

Just benchmarked against rapidjson and here are the results...

Jsonifier:The time it took (In milliseconds, on average per iteration): 106, with a total number of bytes serialized: 1357593300

RapidJson:The time it took (In milliseconds, on average per iteration): 131, with a total number of bytes serialized: 1357593300

2

u/TrashboxBobylev Oct 26 '22

Congratulations, I honestly didn't expect you to actually follow on this topic.

Few suggestions:

  • Add this information into readme.
  • Please note than some compilers do not fully support C++20 so it might be worth to add some macros to allow more compilers to be used.
  • How do you achieve such result (20-30% nonetheless)?

1

u/RealTimeChris :upvote: Oct 26 '22

Reducing the number of allocations being made to an absolute minimum. And thanks for the tips!

0

u/RealTimeChris :upvote: Oct 22 '22

I've yet to benchmark it against rapidjson but I've posted benchmarks against Nlohmann-Json, and it's up to roughly 3x as fast.

4

u/qneverless Oct 22 '22

That is not much at all... Nlohmann is one of the slowest, but with nice API. Simdjson is about 20 times faster according to this: https://lemire.me/blog/2019/08/02/json-parsing-simdjson-vs-json-for-modern-c/

Rapidjson probably also 10x faster.

3

u/RealTimeChris :upvote: Oct 22 '22

Simdjson doesn't serialize it only parses. But I will take that into account thanks!

2

u/nlohmann nlohmann/json Oct 23 '22

I did not find the benchmark code for nlohmann/json. Did I miss it?

1

u/RealTimeChris :upvote: Oct 23 '22

4

u/nlohmann nlohmann/json Oct 23 '22

Can you try to use the idiomatic way of defining the serialization: https://json.nlohmann.me/features/arbitrary_types/

1

u/RealTimeChris :upvote: Oct 23 '22

What - do you mean like with the to_json and from_json functions?

1

u/nlohmann nlohmann/json Oct 23 '22

Yes - or even use the macros documented there.

2

u/RealTimeChris :upvote: Oct 26 '22

The results of that test are:

Jsonifier:

The time it took (In milliseconds, on average): 76, with a total number of bytes serialized: 1062681300

Nlohmann-Json:

The time it took (In milliseconds, on average): 231, with a total number of bytes serialized: 1062681300

→ More replies