mirror of
https://github.com/NixOS/nix
synced 2025-06-27 08:31:16 +02:00
Move path info caching from BinaryCacheStore to Store
Caching path info is generally useful. For instance, it speeds up "nix path-info -rS /run/current-system" (i.e. showing the closure sizes of all paths in the closure of the current system) from 5.6s to 0.15s. This also eliminates some APIs like Store::queryDeriver() and Store::queryReferences().
This commit is contained in:
parent
608b0265e1
commit
e0204f8d46
21 changed files with 318 additions and 353 deletions
|
@ -225,10 +225,48 @@ Path computeStorePathForText(const string & name, const string & s,
|
|||
}
|
||||
|
||||
|
||||
void Store::queryReferences(const Path & path, PathSet & references)
|
||||
bool Store::isValidPath(const Path & storePath)
|
||||
{
|
||||
ValidPathInfo info = queryPathInfo(path);
|
||||
references.insert(info.references.begin(), info.references.end());
|
||||
{
|
||||
auto state_(state.lock());
|
||||
auto res = state_->pathInfoCache.get(storePath);
|
||||
if (res) {
|
||||
stats.narInfoReadAverted++;
|
||||
return *res != 0;
|
||||
}
|
||||
}
|
||||
|
||||
return isValidPathUncached(storePath);
|
||||
}
|
||||
|
||||
|
||||
ref<const ValidPathInfo> Store::queryPathInfo(const Path & storePath)
|
||||
{
|
||||
{
|
||||
auto state_(state.lock());
|
||||
auto res = state_->pathInfoCache.get(storePath);
|
||||
if (res) {
|
||||
stats.narInfoReadAverted++;
|
||||
if (!*res)
|
||||
throw InvalidPath(format("path ‘%s’ is not valid") % storePath);
|
||||
return ref<ValidPathInfo>(*res);
|
||||
}
|
||||
}
|
||||
|
||||
auto info = queryPathInfoUncached(storePath);
|
||||
|
||||
{
|
||||
auto state_(state.lock());
|
||||
state_->pathInfoCache.upsert(storePath, info);
|
||||
stats.pathInfoCacheSize = state_->pathInfoCache.size();
|
||||
}
|
||||
|
||||
if (!info) {
|
||||
stats.narInfoMissing++;
|
||||
throw InvalidPath(format("path ‘%s’ is not valid") % storePath);
|
||||
}
|
||||
|
||||
return ref<ValidPathInfo>(info);
|
||||
}
|
||||
|
||||
|
||||
|
@ -243,19 +281,19 @@ string Store::makeValidityRegistration(const PathSet & paths,
|
|||
for (auto & i : paths) {
|
||||
s += i + "\n";
|
||||
|
||||
ValidPathInfo info = queryPathInfo(i);
|
||||
auto info = queryPathInfo(i);
|
||||
|
||||
if (showHash) {
|
||||
s += printHash(info.narHash) + "\n";
|
||||
s += (format("%1%\n") % info.narSize).str();
|
||||
s += printHash(info->narHash) + "\n";
|
||||
s += (format("%1%\n") % info->narSize).str();
|
||||
}
|
||||
|
||||
Path deriver = showDerivers ? info.deriver : "";
|
||||
Path deriver = showDerivers ? info->deriver : "";
|
||||
s += deriver + "\n";
|
||||
|
||||
s += (format("%1%\n") % info.references.size()).str();
|
||||
s += (format("%1%\n") % info->references.size()).str();
|
||||
|
||||
for (auto & j : info.references)
|
||||
for (auto & j : info->references)
|
||||
s += j + "\n";
|
||||
}
|
||||
|
||||
|
@ -263,6 +301,12 @@ string Store::makeValidityRegistration(const PathSet & paths,
|
|||
}
|
||||
|
||||
|
||||
const Store::Stats & Store::getStats()
|
||||
{
|
||||
return stats;
|
||||
}
|
||||
|
||||
|
||||
ValidPathInfo decodeValidPathInfo(std::istream & str, bool hashGiven)
|
||||
{
|
||||
ValidPathInfo info;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue