Skip to content

Commit

Permalink
Use <nlohmann/json_fwd.hpp>. (#1472)
Browse files Browse the repository at this point in the history
We identified recompiling JSON templates to contribute noticably
to the compile time:

    **** Templates that took longest to instantiate:
    16889 ms: nlohmann::basic_json<>::parse<const char *> (42 times, avg 402 ms)
    12363 ms: nlohmann::basic_json<>::basic_json (127 times, avg 97 ms)
    10129 ms: nlohmann::detail::parser<nlohmann::basic_json<>, nlohmann::detail::i... (42 times, avg 241 ms)
     7934 ms: nlohmann::detail::parser<nlohmann::basic_json<>, nlohmann::detail::i... (42 times, avg 188 ms)
     6145 ms: nlohmann::basic_json<>::json_value::json_value (211 times, avg 29 ms)

Fortunately, we can avoid the issue by using a forward declaration.
  • Loading branch information
1uc authored Sep 30, 2024
1 parent 2cc6cc1 commit 6df0d13
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/printer/json_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "printer/json_printer.hpp"
#include "utils/logger.hpp"

#include <nlohmann/json.hpp>

namespace nmodl {
namespace printer {
Expand Down
2 changes: 1 addition & 1 deletion src/printer/json_printer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* \brief \copybrief nmodl::printer::JSONPrinter
*/

#include <nlohmann/json.hpp>
#include <nlohmann/json_fwd.hpp>

#include <fstream>
#include <iostream>
Expand Down
1 change: 1 addition & 0 deletions src/visitors/perf_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "visitors/perf_visitor.hpp"

#include <cassert>
#include <utility>

#include "ast/all.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/visitors/visitor_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <map>
#include <memory>
#include <nlohmann/json.hpp>
#include <string>

#include "ast/all.hpp"
Expand Down
2 changes: 2 additions & 0 deletions test/unit/visitor/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "visitors/json_visitor.hpp"
#include "visitors/visitor_utils.hpp"

#include <nlohmann/json.hpp>

using json = nlohmann::json;

using namespace nmodl;
Expand Down

0 comments on commit 6df0d13

Please sign in to comment.