Skip to content

PosixSourceAccessor: Use concurrent_flat_map #13478

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

edolstra
Copy link
Member

Motivation

This should be more performant than SharedSync<std::unordered_map>.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@@ -90,23 +90,21 @@ bool PosixSourceAccessor::pathExists(const CanonPath & path)

std::optional<struct stat> PosixSourceAccessor::cachedLstat(const CanonPath & path)
{
static SharedSync<std::unordered_map<Path, std::optional<struct stat>>> _cache;
using Cache = boost::concurrent_flat_map<Path, std::optional<struct stat>>;
static Cache cache;
Copy link
Contributor

@xokdvium xokdvium Jul 15, 2025

Choose a reason for hiding this comment

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

Is there any reason why this cache is a global? I was really confused by this when reading through the code some time prior.

Copy link
Member

Choose a reason for hiding this comment

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

Yes that is suspicious, when there can be different ones of these with different roots

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a reason it shouldn't be global? There can be any number of instances of PosixSourceAccessor, but they all represent the same filesystem.

Copy link
Member

Choose a reason for hiding this comment

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

No they don't, because of the root field.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah but the root field is included in the cache keys.

Copy link
Member

Choose a reason for hiding this comment

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

Oh. OK that does work, but I would still prefer less global state. It is just bad luck for things like forking, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants