-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Precompiled JSON library? #1842
Comments
The library heavily relies on templates, so I am not sure how to achieve this. Any ideas? Apart from this, the multi-header variant contains a header with forward declarations - maybe this can help in the meantime. |
@tawmoto Does your compiler support precompiled headers? I've made good experience with that for getting the compilation times down. I have not used it with this library though. |
@nlohmann I will try the forward declarations. It's very hard for me to convince my colleagues to switch from cJSON to nlohmann json for this reason, although I love your library, it's fantastic. We use a lot precompiled libraries (openssl, curl, json, etc) with great results in compilation time. Because of this problem (big header), we switched from Catch2 to google test, which we precompile. I really think of a solution to make it work in both situations. :-) @t-b Yes, that is my idea also, I will try this. The problem is that we compile with 4 compilers (gcc 5.5, 8.3, clang and VS2019) and I have to implement PCH for all of them in order to convince my colleagues. Thank you both for your answers! 👍 |
I've used this library precompiled under MSVC, Clang, Objective C++. |
Could you share some experiences regarding compile times? |
I don't have any data, but the compile times are very reasonable. |
I generated a PCH but unfortunetaly it's huge, 61MB!
Perhaps the library is better suited for big projects, I have multiple small projects: 8 sloc, 15 sloc, 50 sloc. The Thank you guys for all your help.:) |
If you don't already have a PCH for , , , and the like, then you're going to get those included in this PCH. What effect did it have on your compile time? Are you comparing your compile time to something including all the standard headers with and without a PCH? |
@gregmarr I could not make the PCH to work, but a 61MB PCH inside a 10MB project is not possible for my team, unfortunetaly. |
We tried to use nlohmann::json across different executable and libraries in embedded system. It would save a lot of flash space if we could compile nlohmann::json into a shared library. |
The library is heavily using templates, both for the internal types and for features like creating an array from an iterator range of any STL containers. I have no idea how to make a shared library out of this. However, though I could reproduce the size of the PCH, the binaries are usually much smaller binaries. For instance, a small pretty printer #include <nlohmann/json.hpp>
#include <iostream>
int main()
{
nlohmann::json j;
std::cin >> j;
std::cout << j.dump(2) << std::endl;
} compiles to a 68 KB binary ( |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi,
Is there a way to precompile the JSON library, instead of including a 22k LOC header file?
The compilation times increased dramatically when trying to switch from cJSOn (300 LOC heeader file) to nlohmann JSON. If we never modify that code, I see no point of recompiling everytime 22k LOC if we can have it precompiled.
We love the library but the single-include header is too big, I know that Catch2 wants to drop also the single-header because of this issue.
There are multiple "solutions" to this, but none of them is elegant enough (frw declarations, etc).
Thanks! 👍
The text was updated successfully, but these errors were encountered: