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

libstore: change max-jobs default to auto #9039

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Enzime
Copy link
Member

@Enzime Enzime commented Sep 25, 2023

Motivation

Non-NixOS users who install Nix will have a poor experience as the default is 1 especially when building derivations with many dependencies.

Priorities

Add 👍 to pull requests you find important.

src/libstore/globals.cc Outdated Show resolved Hide resolved
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

Good to stay in sync with NixOS, which has provided a better out of the box experience with respect to the max-jobs option.

src/libutil/util.hh Outdated Show resolved Hide resolved
@@ -147,15 +147,14 @@ public:
"the log to show if a build fails."};

MaxBuildJobsSetting maxBuildJobs{
this, 1, "max-jobs",
this, getMaxThreads(), "max-jobs",
Copy link
Member

Choose a reason for hiding this comment

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

A default of getMaxThreads() makes documentation generation non-reproducible. It may be better to represent the "auto" value explicitly, e.g. by changing the type of this option to std::optional<unsigned int>, with "auto" encoded as std::nullopt.

src/libutil/util.hh Outdated Show resolved Hide resolved
src/libstore/globals.hh Outdated Show resolved Hide resolved
@github-actions github-actions bot added the store Issues and pull requests concerning the Nix store label Sep 28, 2023
{
if (str == "auto") return std::max(1U, std::thread::hardware_concurrency());
return value.value_or(getMaxThreads());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return value.value_or(getMaxThreads());
// Settings should be fast to retrieve. Ignore changes to core count - rare, and process lifespan is often short.
unsigned int cachedThreads = getMaxThreads();
return value.value_or(cachedThreads);

@fricklerhandwerk
Copy link
Contributor

fricklerhandwerk commented Oct 20, 2023

Triaged in Nix team meeting 2023-10-13:

  • This is good to go in principle, assigned to @roberth
  • Would be nice to generalize the auto mechanism as a follow-up
  • @roberth: Subclassing Setting<T> is hard when the parsing implementation for T does not exist in a related type class about parsing, or if you want a custom parser for the type.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-10-13-nix-team-meeting-minutes-94/34395/1

@github-actions github-actions bot added documentation with-tests Issues related to testing. PRs with tests have some priority and removed store Issues and pull requests concerning the Nix store labels Nov 4, 2023
@github-actions github-actions bot added the fetching Networking with the outside (non-Nix) world, input locking label Nov 4, 2023
@Enzime
Copy link
Member Author

Enzime commented Nov 4, 2023

Instead of improving docs reproducibility by changing the type (which I tried but ran into some gnarly template related issues), I decided to extend Settings to have a defaultText parameter which allows you to add a hardcoded string as the default value in the docs.

This latter part would've most likely been necessary either way as we would've wanted some way to render std::nullopt as auto in the docs.

src/libstore/globals.cc Show resolved Hide resolved
const std::set<std::string> & aliases = {})
: BaseSetting<unsigned int>(def, true, name, description, aliases)
const std::set<std::string> & aliases = {},
const std::optional<std::string> defaultText = std::nullopt)
Copy link
Contributor

Choose a reason for hiding this comment

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

all these constructor parameters should ideally be by value and then std::moved further. Then the way the caller calls it (with lvalues or rvalues) unnecessary copies can be avoided.

: BaseSetting<Paths>(def, true, name, description, aliases)
const std::set<std::string> & aliases = {},
const std::optional<std::string> defaultText = std::nullopt)
: BaseSetting<Paths>(def, name, description, aliases, defaultText)
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

: BaseSetting<Path>(def, true, name, description, aliases)
const std::set<std::string> & aliases,
const std::optional<std::string> defaultText)
: BaseSetting<Path>(def, name, description, aliases, defaultText)
Copy link
Contributor

Choose a reason for hiding this comment

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

ok there are many possibilities to do call-by-value optimizations in constructors here. maybe just leave it as is and i open a pr on that on another occasion.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, maybe... wait, is this meant to be const references to string literals in the code where all the settings are defined, and none of them are dynamic? @Ericson2314

std::optional<ExperimentalFeature> experimentalFeature = std::nullopt)
: AbstractSetting(name, description, aliases, experimentalFeature)
, value(def)
, defaultValue(def)
, documentDefault(documentDefault)
, defaultText(defaultText)
Copy link
Contributor

Choose a reason for hiding this comment

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

plz use std::move here as this is by value

std::optional<ExperimentalFeature> experimentalFeature = std::nullopt)
: BaseSetting<T>(def, documentDefault, name, description, aliases, experimentalFeature)
: BaseSetting<T>(def, name, description, aliases, defaultText, experimentalFeature)
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

@DavHau
Copy link
Member

DavHau commented Dec 27, 2023

What's the status of this? I'd really like to see this change deployed to the masses. Thanks for the work so far!

@roberth roberth added the settings Settings, global flags, nix.conf label Mar 10, 2024
@roberth
Copy link
Member

roberth commented Mar 10, 2024

Oh no, I dropped the ball on this.
The solution lgtm, but there's a bunch of conflicts. @Enzime would you be willing to merge/rebase?

@Enzime
Copy link
Member Author

Enzime commented Mar 21, 2024

@roberth I'm quite busy lately so I don't have the time to rebase this at the moment, if anyone's interested in picking up this PR, feel free to, otherwise I'll come back to it eventually when I get more time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation fetching Networking with the outside (non-Nix) world, input locking settings Settings, global flags, nix.conf with-tests Issues related to testing. PRs with tests have some priority
Projects
Status: 🏁 Review
Development

Successfully merging this pull request may close these issues.

7 participants