Merge pull request #10812 from Mic92/build-perf

Remove 100s of CPU time (10%) from build times (1465s -> 1302s)
This commit is contained in:
Robert Hensing 2024-05-31 13:28:24 +02:00 committed by GitHub
commit 84e116379c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 59 additions and 31 deletions

View file

@ -28,13 +28,13 @@
#include <algorithm>
#include <chrono>
#include <iostream>
#include <sstream>
#include <cstring>
#include <optional>
#include <unistd.h>
#include <sys/time.h>
#include <fstream>
#include <functional>
#include <iostream>
#include <nlohmann/json.hpp>
#include <boost/container/small_vector.hpp>

View file

@ -20,8 +20,6 @@
#pragma clang diagnostic ignored "-Wunneeded-internal-declaration"
#endif
#include <boost/lexical_cast.hpp>
#include "nixexpr.hh"
#include "parser-tab.hh"
@ -129,9 +127,10 @@ or { return OR_KW; }
{ID} { yylval->id = {yytext, (size_t) yyleng}; return ID; }
{INT} { errno = 0;
try {
yylval->n = boost::lexical_cast<int64_t>(yytext);
} catch (const boost::bad_lexical_cast &) {
std::optional<int64_t> numMay = string2Int<int64_t>(yytext);
if (numMay.has_value()) {
yylval->n = *numMay;
} else {
throw ParseError(ErrorInfo{
.msg = HintFmt("invalid integer '%1%'", yytext),
.pos = state->positions[CUR_POS],

View file

@ -6,6 +6,7 @@
#include "print.hh"
#include <cstdlib>
#include <sstream>
namespace nix {

View file

@ -26,6 +26,7 @@
#include <algorithm>
#include <cstring>
#include <sstream>
#include <regex>
#ifndef _WIN32

View file

@ -1,5 +1,6 @@
#include <limits>
#include <unordered_set>
#include <sstream>
#include "print.hh"
#include "ansicolor.hh"

View file

@ -7,6 +7,7 @@
#include <atomic>
#include <map>
#include <thread>
#include <sstream>
#include <iostream>
#include <chrono>

View file

@ -18,6 +18,7 @@
#include <future>
#include <regex>
#include <fstream>
#include <sstream>
#include <nlohmann/json.hpp>

View file

@ -19,6 +19,8 @@
# include "monitor-fd.hh"
#endif
#include <sstream>
namespace nix::daemon {
Sink & operator << (Sink & sink, const Logger::Fields & fields)

View file

@ -148,7 +148,7 @@ static Machine parseBuilderLine(const std::set<std::string> & defaultSystems, co
};
auto parseFloatField = [&](size_t fieldIndex) {
const auto result = string2Int<float>(tokens[fieldIndex]);
const auto result = string2Float<float>(tokens[fieldIndex]);
if (!result) {
throw FormatError("bad machine specification: failed to convert column #%lu in a row: '%s' to 'float'", fieldIndex, line);
}

View file

@ -7,6 +7,7 @@
#include "file-system.hh"
#include "processes.hh"
#include "signals.hh"
#include <math.h>
#ifdef __APPLE__
# include <mach-o/dyld.h>

View file

@ -20,8 +20,6 @@
#endif
#include <signal.h>
#include <boost/lexical_cast.hpp>
#include <atomic>
#include <functional>
#include <map>

View file

@ -8,6 +8,7 @@
#include "position.hh"
#include <atomic>
#include <sstream>
#include <nlohmann/json.hpp>
#include <iostream>

View file

@ -12,8 +12,6 @@
#include <unistd.h>
#include <signal.h>
#include <boost/lexical_cast.hpp>
#include <atomic>
#include <functional>
#include <map>

View file

@ -7,6 +7,8 @@
#include <regex>
#include <sodium.h>
#include <boost/lexical_cast.hpp>
#include <stdint.h>
#ifdef NDEBUG
#error "Nix may not be built with assertions disabled (i.e. with -DNDEBUG)."
@ -111,6 +113,43 @@ std::string rewriteStrings(std::string s, const StringMap & rewrites)
return s;
}
template<class N>
std::optional<N> string2Int(const std::string_view s)
{
if (s.substr(0, 1) == "-" && !std::numeric_limits<N>::is_signed)
return std::nullopt;
try {
return boost::lexical_cast<N>(s.data(), s.size());
} catch (const boost::bad_lexical_cast &) {
return std::nullopt;
}
}
// Explicitly instantiated in one place for faster compilation
template std::optional<unsigned char> string2Int<unsigned char>(const std::string_view s);
template std::optional<unsigned short> string2Int<unsigned short>(const std::string_view s);
template std::optional<unsigned int> string2Int<unsigned int>(const std::string_view s);
template std::optional<unsigned long> string2Int<unsigned long>(const std::string_view s);
template std::optional<unsigned long long> string2Int<unsigned long long>(const std::string_view s);
template std::optional<signed char> string2Int<signed char>(const std::string_view s);
template std::optional<signed short> string2Int<signed short>(const std::string_view s);
template std::optional<signed int> string2Int<signed int>(const std::string_view s);
template std::optional<signed long> string2Int<signed long>(const std::string_view s);
template std::optional<signed long long> string2Int<signed long long>(const std::string_view s);
template<class N>
std::optional<N> string2Float(const std::string_view s)
{
try {
return boost::lexical_cast<N>(s.data(), s.size());
} catch (const boost::bad_lexical_cast &) {
return std::nullopt;
}
}
template std::optional<double> string2Float<double>(const std::string_view s);
template std::optional<float> string2Float<float>(const std::string_view s);
bool hasPrefix(std::string_view s, std::string_view prefix)
{

View file

@ -5,7 +5,6 @@
#include "error.hh"
#include "logging.hh"
#include <boost/lexical_cast.hpp>
#include <functional>
#include <map>
@ -102,16 +101,7 @@ std::string rewriteStrings(std::string s, const StringMap & rewrites);
* Parse a string into an integer.
*/
template<class N>
std::optional<N> string2Int(const std::string_view s)
{
if (s.substr(0, 1) == "-" && !std::numeric_limits<N>::is_signed)
return std::nullopt;
try {
return boost::lexical_cast<N>(s.data(), s.size());
} catch (const boost::bad_lexical_cast &) {
return std::nullopt;
}
}
std::optional<N> string2Int(const std::string_view s);
/**
* Like string2Int(), but support an optional suffix 'K', 'M', 'G' or
@ -141,14 +131,7 @@ N string2IntWithUnitPrefix(std::string_view s)
* Parse a string into a float.
*/
template<class N>
std::optional<N> string2Float(const std::string_view s)
{
try {
return boost::lexical_cast<N>(s.data(), s.size());
} catch (const boost::bad_lexical_cast &) {
return std::nullopt;
}
}
std::optional<N> string2Float(const std::string_view s);
/**

View file

@ -9,8 +9,9 @@
#include "eval-inline.hh"
#include "profiles.hh"
#include "print-ambiguous.hh"
#include <limits>
#include <limits>
#include <sstream>
namespace nix {

View file

@ -14,6 +14,7 @@
#include <iterator>
#include <memory>
#include <sstream>
#include <nlohmann/json.hpp>
#include <algorithm>