HOT SALE: 15% off your build times!

This was achieved by running maintainers/buildtime_report.sh on the
build directory of a meson build, then asking "why the heck is json
eating our build times", and strategically moving the json using bits
out of widely included headers.

It turns out that putting literally any metrics whatsoever into the
build had immediate and predictable results.

Results are 1382.5s frontend time -> 1175.4s frontend time, back end
time approximately invariant.

Related: #159

Change-Id: I7edea95c8536203325c8bb4dae5f32d727a21b2d
This commit is contained in:
jade 2024-03-18 23:06:34 -07:00 committed by jade
parent 412a9c9f67
commit edba570664
13 changed files with 64 additions and 34 deletions

View file

@ -1,4 +1,5 @@
#include <limits>
#include <span>
#include <unordered_set>
#include "print.hh"

View file

@ -13,6 +13,7 @@
#include "topo-sort.hh"
#include "callback.hh"
#include "local-store.hh" // TODO remove, along with remaining downcasts
#include "logging-json.hh"
#include <regex>
#include <queue>

View file

@ -8,6 +8,7 @@
#include "common-protocol.hh"
#include "common-protocol-impl.hh"
#include "fs-accessor.hh"
#include "json-utils.hh"
#include <boost/container/small_vector.hpp>
#include <nlohmann/json.hpp>

View file

@ -4,6 +4,8 @@
#include <nlohmann/json.hpp>
#include "config.hh"
#include "json-utils.hh"
// Required for instances of to_json and from_json for ExperimentalFeature
#include "experimental-features-json.hh"
namespace nix {
template<typename T>

View file

@ -2,6 +2,7 @@
#include "args/root.hh"
#include "hash.hh"
#include "json-utils.hh"
#include "experimental-features-json.hh"
#include <glob.h>

View file

@ -0,0 +1,29 @@
#pragma once
///@file
#include "experimental-features.hh"
#include "json-utils.hh"
namespace nix {
/**
* Compute the documentation of all experimental features.
*
* See `doc/manual` for how this information is used.
*/
nlohmann::json documentExperimentalFeatures();
/**
* Semi-magic conversion to and from json.
* See the nlohmann/json readme for more details.
*/
void to_json(nlohmann::json &, const ExperimentalFeature &);
void from_json(const nlohmann::json &, ExperimentalFeature &);
/**
* It is always rendered as a string
*/
template<>
struct json_avoids_null<ExperimentalFeature> : std::true_type {};
};

View file

@ -1,4 +1,6 @@
#include "experimental-features.hh"
// Required for instances of to_json and from_json for ExperimentalFeature
#include "experimental-features-json.hh"
#include "util.hh"
#include "nlohmann/json.hpp"

View file

@ -1,9 +1,7 @@
#pragma once
///@file
#include "comparator.hh"
#include "error.hh"
#include "json-utils.hh"
#include "types.hh"
namespace nix {
@ -52,13 +50,6 @@ const std::optional<ExperimentalFeature> parseExperimentalFeature(
*/
std::string_view showExperimentalFeature(const ExperimentalFeature);
/**
* Compute the documentation of all experimental features.
*
* See `doc/manual` for how this information is used.
*/
nlohmann::json documentExperimentalFeatures();
/**
* Shorthand for `str << showExperimentalFeature(feature)`.
*/
@ -87,17 +78,4 @@ public:
MissingExperimentalFeature(ExperimentalFeature missingFeature);
};
/**
* Semi-magic conversion to and from json.
* See the nlohmann/json readme for more details.
*/
void to_json(nlohmann::json &, const ExperimentalFeature &);
void from_json(const nlohmann::json &, ExperimentalFeature &);
/**
* It is always rendered as a string
*/
template<>
struct json_avoids_null<ExperimentalFeature> : std::true_type {};
}

View file

@ -0,0 +1,23 @@
#pragma once
///@file logging-json.hh
///
///@brief Logging functions for json specifically, split due to the cost of
///including nlohmann.
#include "logging.hh"
#include <nlohmann/json_fwd.hpp>
namespace nix {
std::optional<nlohmann::json> parseJSONMessage(const std::string & msg);
bool handleJSONLogMessage(nlohmann::json & json,
const Activity & act, std::map<ActivityId, Activity> & activities,
bool trusted);
bool handleJSONLogMessage(const std::string & msg,
const Activity & act, std::map<ActivityId, Activity> & activities,
bool trusted);
};

View file

@ -5,8 +5,6 @@
#include "error.hh"
#include "config.hh"
#include <nlohmann/json_fwd.hpp>
namespace nix {
typedef enum {
@ -184,16 +182,6 @@ Logger * makeSimpleLogger(bool printBuildLogs = true);
Logger * makeJSONLogger(Logger & prevLogger);
std::optional<nlohmann::json> parseJSONMessage(const std::string & msg);
bool handleJSONLogMessage(nlohmann::json & json,
const Activity & act, std::map<ActivityId, Activity> & activities,
bool trusted);
bool handleJSONLogMessage(const std::string & msg,
const Activity & act, std::map<ActivityId, Activity> & activities,
bool trusted);
/**
* suppress msgs > this
*/

View file

@ -50,6 +50,7 @@ libutil_headers = files(
'error.hh',
'exit.hh',
'experimental-features.hh',
'experimental-features-json.hh',
'finally.hh',
'fmt.hh',
'git.hh',
@ -59,6 +60,7 @@ libutil_headers = files(
'json-impls.hh',
'json-utils.hh',
'logging.hh',
'logging-json.hh',
'lru-cache.hh',
'monitor-fd.hh',
'namespaces.hh',

View file

@ -13,6 +13,7 @@
#include "finally.hh"
#include "loggers.hh"
#include "markdown.hh"
#include "experimental-features-json.hh"
#include <sys/types.h>
#include <sys/socket.h>

View file

@ -3,6 +3,7 @@
#include "debug-char.hh"
#include "types.hh"
#include "util.hh"
#include <ranges>
#include <iostream>
#include <memory>
#include <boost/algorithm/string/trim.hpp>