Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider replacing jsoncpp #6900

Closed
ekpyron opened this issue Jun 4, 2019 · 23 comments · Fixed by #14877
Closed

Consider replacing jsoncpp #6900

ekpyron opened this issue Jun 4, 2019 · 23 comments · Fixed by #14877
Labels
build system 🏗️ low impact Changes are not very noticeable or potential benefits are limited. medium effort Default level of effort must have eventually Something we consider essential but not enough to prevent us from releasing Solidity 1.0 without it. refactor

Comments

@ekpyron
Copy link
Member

ekpyron commented Jun 4, 2019

  • The repo looks like jsoncpp only receives minimal maintenance.
  • The workaround of manually downloading jsoncpp in cmake is evil (we could of course attempt to change that in isolation, but there don't seem to be package updates for jsoncpp e.g. in recent ubuntu either making this a continuing hassle).
  • jsoncpp is neither the fastest nor the smallest nor the most conformant option.
  • There are a number of pretty much drop-in replacements available.
  • We can easily move to a header-only library which pretty much avoids all dependency issues in perpetuity.

I'd suggest to consider replacing jsoncpp with either http://rapidjson.org/ or https://github.com/nlohmann/json (or any other of the available candidates).

Is there any reason for staying with jsoncpp other than the required work a move would be (which I wouldn't expect to actually be too bad)?

Closes #3557.

@christianparpart
Copy link
Member

wrt. nlohmann/json, they state Our whole code consists of a single header file json.hpp, which would be the main reason for me to choose them.

Also the examples he provides in the readme look very convincing to me. => 👍 for this one.

@chriseth
Copy link
Contributor

I had a quick look over nlohmann and found the following two items that might be issues:

@ekpyron
Copy link
Member Author

ekpyron commented Jun 20, 2019

I think while the insertion order of the keys is not preserved, they don't have an "undefined" order - they use a std::map, so in the end the keys will be ordered by string comparison and that's deterministic - but we need to recheck, yes.

Regarding comments I'm not sure - should we allow them even though they are actually not valid json? I know that json-cpp only supports them in a weird way as well (whether a comment is fine depends on whether it's key-comment-comma or key-comma-comment, if I recall correctly).

@nlohmann
Copy link

Hi, I'm the author for nlohmann/json. Please let me know if you need any assistance!

@chriseth
Copy link
Contributor

chriseth commented Jul 1, 2019

@nlohmann great to have you here! Can you comment on the order of keys? Is it a defined order that may be different from the insertion order or can it depend on things like memory layout?

@nlohmann
Copy link

nlohmann commented Jul 1, 2019

We use an std::map internally, so the order when iterating over an object is sorted alphabetically w.r.t. std::string::operator<.

@chriseth
Copy link
Contributor

chriseth commented Jul 1, 2019

Wonderful, thanks!

@aarlt
Copy link
Member

aarlt commented Oct 26, 2019

Ah nice, I just found this issue. @ekpyron I had the same impression and I think it would be nice to replace jsoncpp. Around a year ago I created a branch to replace jsoncpp but somehow I never created a PR (https://github.com/aarlt/solidity/tree/nlohmann-json). I don't remember exactly what the state was, but if you would like to replace jsoncpp with nlohmann/json, I could support you.

@nlohmann
Copy link

As I wrote earlier, just let me know if you need assistance!

@ekpyron
Copy link
Member Author

ekpyron commented Nov 4, 2019

I brought this up in our weekly call earlier and @chriseth said we should postpone this until after 0.6.0 is released.
However aarlt@1329c25 is a great reference for estimating how much effort this will be - it doesn't look too bad, so I think we can do this quickly after 0.6.0.

@axic
Copy link
Member

axic commented Nov 26, 2019

nlohmann's seems to be better in every single benchmark compared to jsoncpp: https://github.com/miloyip/nativejson-benchmark

@chriseth
Copy link
Contributor

Are benchmarks the benchmark? I would say it is more important that the code is easy to understand and does not create any ambiguities.

@axic
Copy link
Member

axic commented Nov 27, 2019

I think the API of nlohman was quite good, even compared to jsoncpp.

The benchmark categories are:

  • code size
  • parsing speed
  • serialisation speed

There is a huge difference between speeds, which can be an issue with large compilations (large JSON outputs or input). I think this may be the reason people were complaining on compilation speed.

@ekpyron
Copy link
Member Author

ekpyron commented Nov 27, 2019

By the way: @Marenz is having problems problems with the performance of the AST export and import tests, for which I think the json parsing and emitting part is a major bottleneck - so it's not like performance is entirely irrelevant... and regarding readability: just have a quick look at aarlt@1329c25 - the API is very similar to jsoncpp and closer to STL, which I'd consider an advantage.

@ekpyron ekpyron added this to To do in Solidity Technical Debt via automation Nov 27, 2019
@axic
Copy link
Member

axic commented Apr 25, 2020

Regarding comments I'm not sure - should we allow them even though they are actually not valid json? I know that json-cpp only supports them in a weird way as well (whether a comment is fine depends on whether it's key-comment-comma or key-comma-comment, if I recall correctly).

I would say there is no point supporting comments when they are not a valid JSON feature. IIRC we have them disabled as much as jsoncpp allows disabling them.

Also apparently nlohman-json now supports CBOR integration: https://github.com/nlohmann/json#binary-formats-bson-cbor-messagepack-and-ubjson

This means we could in theory replace our code or at least replace it in the tests. However this is not a pressing issue as our small CBOR code works well and as intended.

@maximegmd
Copy link

Dropping another suggestion that favors performance: https://github.com/simdjson/simdjson

The API is also quite straight forward.

@Zachinquarantine
Copy link
Contributor

just curious, what is https://github.com/ethereum/solidity/blob/develop/scripts/install_obsolete_jsoncpp_1_7_4.sh and why does it exist?

@cameel
Copy link
Member

cameel commented Aug 26, 2021

It used to be needed in CI on macOS and older Ubuntu versions: #4073 . For Ubuntu It was later replaced with a package (#6453). For macOS we still use it though. osx_install_dependencies.sh runs that script.

I'm not completely sure why macOS needs specifically 1.7.4 but there's a comment comment in one of these PRs saying that it's somehow related to how we download and build it on our own during cmake setup:

Would be nicer to get rid of the script altogether, but I'd suggest to keep it for the macos build for now and remove it, once we got rid of the whole build-json-cpp-on-our-own-mess in general (then we can just use 1.8.4 from homebrew instead - they in fact have it: https://formulae.brew.sh/formula/jsoncpp).

@github-actions
Copy link

This issue has been marked as stale due to inactivity for the last 90 days.
It will be automatically closed in 7 days.

@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Feb 23, 2023
@cameel
Copy link
Member

cameel commented Feb 23, 2023

I'm going to keep this one open. It may not be high on our priority list, but I think we should move away from jsoncpp eventually.

@cameel cameel added medium effort Default level of effort low impact Changes are not very noticeable or potential benefits are limited. should have We like the idea but it’s not important enough to be a part of the roadmap. refactor and removed stale The issue/PR was marked as stale because it has been open for too long. labels Feb 23, 2023
@github-actions
Copy link

This issue has been marked as stale due to inactivity for the last 90 days.
It will be automatically closed in 7 days.

@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label May 25, 2023
@github-actions
Copy link

github-actions bot commented Jun 1, 2023

Hi everyone! This issue has been automatically closed due to inactivity.
If you think this issue is still relevant in the latest Solidity version and you have something to contribute, feel free to reopen.
However, unless the issue is a concrete proposal that can be implemented, we recommend starting a language discussion on the forum instead.

@github-actions github-actions bot added the closed due inactivity The issue/PR was automatically closed due to inactivity. label Jun 1, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 1, 2023
Solidity Technical Debt automation moved this from Backlog to Done Jun 1, 2023
@ekpyron ekpyron reopened this Jun 7, 2023
Solidity Technical Debt automation moved this from Done to In progress Jun 7, 2023
@ekpyron ekpyron added must have eventually Something we consider essential but not enough to prevent us from releasing Solidity 1.0 without it. and removed should have We like the idea but it’s not important enough to be a part of the roadmap. closed due inactivity The issue/PR was automatically closed due to inactivity. stale The issue/PR was marked as stale because it has been open for too long. labels Jun 7, 2023
@cameel
Copy link
Member

cameel commented May 23, 2024

This was implemented by #14877.

@cameel cameel closed this as completed May 23, 2024
Solidity Technical Debt automation moved this from In progress to Done May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build system 🏗️ low impact Changes are not very noticeable or potential benefits are limited. medium effort Default level of effort must have eventually Something we consider essential but not enough to prevent us from releasing Solidity 1.0 without it. refactor
Projects
10 participants