Skip to content

Commit

Permalink
reduce copies during drv parsing
Browse files Browse the repository at this point in the history
many paths need not be heap-allocated, and derivation env name/valye
pairs can be moved into the map.

before:

Benchmark 1: nix eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system'
  Time (mean ± σ):      6.883 s ±  0.016 s    [User: 5.250 s, System: 1.424 s]
  Range (min … max):    6.860 s …  6.905 s    10 runs

after:

Benchmark 1: nix eval --raw --impure --expr 'with import <nixpkgs/nixos> {}; system'
  Time (mean ± σ):      6.868 s ±  0.027 s    [User: 5.194 s, System: 1.466 s]
  Range (min … max):    6.828 s …  6.913 s    10 runs
  • Loading branch information
pennae committed Dec 28, 2023
1 parent 9f8b18b commit 475fc07
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/libstore/derivations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ static void validatePath(std::string_view s) {
throw FormatError("bad path '%1%' in derivation", s);
}

static Path parsePath(ParseContext & str)
static BackedStringView parsePath(ParseContext & str)
{
auto s = parseString(str).toOwned();
validatePath(s);
auto s = parseString(str);
validatePath(*s);
return s;
}

Expand All @@ -260,7 +260,7 @@ static StringSet parseStrings(ParseContext & str, bool arePaths)
StringSet res;
expect(str, "[");
while (!endOfList(str))
res.insert(arePaths ? parsePath(str) : parseString(str).toOwned());
res.insert((arePaths ? parsePath(str) : parseString(str)).toOwned());
return res;
}

Expand Down Expand Up @@ -432,9 +432,9 @@ Derivation parseDerivation(
expect(str, ",[");
while (!endOfList(str)) {
expect(str, "(");
Path drvPath = parsePath(str);
auto drvPath = parsePath(str);
expect(str, ",");
drv.inputDrvs.map.insert_or_assign(store.parseStorePath(drvPath), parseDerivedPathMapNode(store, str, version));
drv.inputDrvs.map.insert_or_assign(store.parseStorePath(*drvPath), parseDerivedPathMapNode(store, str, version));
expect(str, ")");
}

Expand All @@ -453,7 +453,7 @@ Derivation parseDerivation(
expect(str, "("); auto name = parseString(str).toOwned();
expect(str, ","); auto value = parseString(str).toOwned();
expect(str, ")");
drv.env[name] = value;
drv.env.insert_or_assign(std::move(name), std::move(value));
}

expect(str, ")");
Expand Down

0 comments on commit 475fc07

Please sign in to comment.