Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchToStore(): Avoid duplicate copying if the input is already a store path #10511

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/libfetchers/fetch-to-store.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "fetch-to-store.hh"
#include "fetchers.hh"
#include "cache.hh"
#include "posix-source-accessor.hh"

namespace nix {

Expand All @@ -13,8 +14,16 @@ StorePath fetchToStore(
PathFilter * filter,
RepairFlag repair)
{
// FIXME: add an optimisation for the case where the accessor is
// a `PosixSourceAccessor` pointing to a store path.
if (path.accessor->isStorePath
&& path.path.isRoot()
&& method == FileIngestionMethod::Recursive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What goes wrong if we skip this? I am trying to special-case NAR hashing less in Nix currently.

Suggested change
&& method == FileIngestionMethod::Recursive

&& !filter)
{
if (auto accessor = path.accessor.dynamic_pointer_cast<PosixSourceAccessor>())
if (auto storePath = store.maybeParseStorePath(accessor->root.string()))
if (storePath->name() == name)
return *storePath;
}

std::optional<fetchers::Cache::Key> cacheKey;

Expand Down
7 changes: 6 additions & 1 deletion src/libfetchers/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ struct PathInputScheme : InputScheme
}
input.attrs.insert_or_assign("lastModified", uint64_t(mtime));

return {makeStorePathAccessor(store, *storePath), std::move(input)};
auto accessor = makeStorePathAccessor(store, *storePath);

/* Optimize fetchToStore() calls on this path. */
accessor->isStorePath = true;

return {accessor, std::move(input)};
}

std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
Expand Down
3 changes: 3 additions & 0 deletions src/libfetchers/unix/mercurial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ struct MercurialInputScheme : InputScheme

accessor->setPathDisplay("«" + input.to_string() + "»");

/* Optimize fetchToStore() calls on this path. */
accessor->isStorePath = true;

return {accessor, input};
}

Expand Down
7 changes: 7 additions & 0 deletions src/libutil/source-accessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ struct SourceAccessor : std::enable_shared_from_this<SourceAccessor>
*/
virtual std::optional<time_t> getLastModified()
{ return std::nullopt; }

/**
* Whether this is a store path using
* FileIngestionMethod::Recursive. This is used to optimize
* `fetchToStore()`.
*/
bool isStorePath = false;
};

/**
Expand Down
Loading