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

Use YAML for config #352

Merged
merged 10 commits into from
Nov 28, 2024
Merged

Use YAML for config #352

merged 10 commits into from
Nov 28, 2024

Conversation

shivaraj-bh
Copy link
Member

@shivaraj-bh shivaraj-bh commented Nov 25, 2024

resolves #343

If the flake url is a local path and om.yaml exists in the project root, omnix will not invoke nix eval .#om.

Benchmarked om develop —pre-shell . && om develop —post-shell . in https://github.com/nammayatri/nammayatri, using YAML config is 14 times faster:

❯ nix run github:nixos/nixpkgs/nixpkgs-unstable#hyperfine -- --warmup 10 './with-yaml/bin/om develop --stage pre-shell . && ./with-yaml/bin/om develop --stage post-shell .' './without-yaml/bin/om develop --stage pre-shell . && ./without-yaml/bin/om develop --stage post-shell .'
Benchmark 1: ./with-yaml/bin/om develop --stage pre-shell . && ./with-yaml/bin/om develop --stage post-shell .
  Time (mean ± σ):      48.8 ms ±   1.2 ms    [User: 20.7 ms, System: 30.4 ms]
  Range (min … max):    46.9 ms …  52.8 ms    59 runs

Benchmark 2: ./without-yaml/bin/om develop --stage pre-shell . && ./without-yaml/bin/om develop --stage post-shell .
  Time (mean ± σ):     725.6 ms ±  13.6 ms    [User: 514.6 ms, System: 258.1 ms]
  Range (min … max):   708.6 ms … 751.8 ms    10 runs

Summary
  ./with-yaml/bin/om develop --stage pre-shell . && ./with-yaml/bin/om develop --stage post-shell . ran
   14.88 ± 0.46 times faster than ./without-yaml/bin/om develop --stage pre-shell . && ./without-yaml/bin/om develop --stage post-shell .

om.yaml used for the benchmark:

health:
  default:
    caches:
      required:
        - "https://nammayatri.cachix.org"
    direnv:
      required: true
    system:
      min_ram: "24G"

om.yaml Outdated Show resolved Hide resolved
Copy link
Member

@srid srid left a comment

Choose a reason for hiding this comment

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

This looks good so far. Can we improve the OmConfig::get interface so as to resolve and avoid unnecessary nix command runs? See #339 (comment)

crates/omnix-common/src/config.rs Outdated Show resolved Hide resolved
@shivaraj-bh
Copy link
Member Author

This looks good so far. Can we improve the OmConfig::get interface so as to resolve and avoid unnecessary nix command runs? See #339 (comment)

Aren’t those nix commands the result of the checks in preShell?

pub async fn develop_on_pre_shell(prj: &Project) -> anyhow::Result<()> {
// Run relevant `om health` checks
let health = NixHealth::from_om_config(&prj.om_config)?;
let nix_info = NixInfo::get()
.await
.as_ref()
.with_context(|| "Unable to gather nix info")?;
let mut relevant_checks: Vec<&'_ dyn Checkable> =
vec![&health.nix_version, &health.rosetta, &health.max_jobs];
if !health.caches.required.is_empty() {
relevant_checks.push(&health.trusted_users);
};

@srid
Copy link
Member

srid commented Nov 27, 2024

Aren’t those nix commands the result of the checks in preShell?

While we can't avoid running nix commands in preShell (for now), we certainly can avoid that in postShell (which too will be run as part of direnv invocation):

image

@shivaraj-bh
Copy link
Member Author

While we can't avoid running nix commands in preShell (for now), we certainly can avoid that in postShell (which too will be run as part of direnv invocation):

Fixed in 1b7c152.

❯ just run develop --stage post-shell .
cargo run -p omnix-cli develop --stage post-shell .
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.28s
     Running `target/debug/om develop --stage post-shell .`
⌨️  Preparing to develop project: .

🍾 Welcome to the omnix project

To run omnix,

────────────────────
just watch <args>
────────────────────

(Now, as you edit the Rust sources, the above will reload!)

🍎🍎 Run 'just' to see more commands. See https://nixos.asia/en/vscode for IDE setup.

@shivaraj-bh
Copy link
Member Author

shivaraj-bh commented Nov 28, 2024

Did a benchmark of running both postShell and preShell comparing master with changes in yaml-config branch using https://github.com/sharkdp/hyperfine

❯ nix run github:nixos/nixpkgs/nixpkgs-unstable#hyperfine -- --warmup 10 './with-yaml/bin/om develop --stage pre-shell . && ./with-yaml/bin/om develop --stage post-shell .' './without-yaml/bin/om develop --stage pre-shell . && ./without-yaml/bin/om develop --stage post-shell .'
Benchmark 1: ./with-yaml/bin/om develop --stage pre-shell . && ./with-yaml/bin/om develop --stage post-shell .
  Time (mean ± σ):     208.7 ms ±   3.7 ms    [User: 6.6 ms, System: 2.3 ms]
  Range (min … max):   203.5 ms … 216.7 ms    14 runs
 
Benchmark 2: ./without-yaml/bin/om develop --stage pre-shell . && ./without-yaml/bin/om develop --stage post-shell .
  Time (mean ± σ):     603.8 ms ±   6.9 ms    [User: 93.0 ms, System: 92.1 ms]
  Range (min … max):   592.2 ms … 612.5 ms    10 runs
 
Summary
  ./with-yaml/bin/om develop --stage pre-shell . && ./with-yaml/bin/om develop --stage post-shell . ran
    2.89 ± 0.06 times faster than ./without-yaml/bin/om develop --stage pre-shell . && ./without-yaml/bin/om develop --stage post-shell .

Here are individual outputs of with-yaml and without-yaml respectively:

❯ ./with-yaml/bin/om develop --stage pre-shell . && ./with-yaml/bin/om develop --stage post-shell .
⌨️  Preparing to develop project: .
❄️  nix --accept-flake-config --version️
❄️  nix --extra-experimental-features nix-command --accept-flake-config show-config --json️
✅ Nix environment is healthy.
⌨️  Preparing to develop project: .

🍾 Welcome to the omnix project

To run omnix,

────────────────────
just watch <args>
────────────────────

(Now, as you edit the Rust sources, the above will reload!)

🍎🍎 Run 'just' to see more commands. See https://nixos.asia/en/vscode for IDE setup.
❯ ./without-yaml/bin/om develop --stage pre-shell . && ./without-yaml/bin/om develop --stage post-shell .
❄️  nix --accept-flake-config --version️
❄️  nix --extra-experimental-features nix-command --accept-flake-config show-config --json️
❄️  nix --accept-flake-config eval '.#om' --json️
⌨️  Preparing to develop project: .
✅ Nix environment is healthy.
❄️  nix --accept-flake-config --version️
❄️  nix --extra-experimental-features nix-command --accept-flake-config show-config --json️
❄️  nix --accept-flake-config eval '.#om' --json️
⌨️  Preparing to develop project: .

🍾 Welcome to the project

(Want to show custom instructions here? Add them to the om.develop.default.readme field in your flake.nix file)

@shivaraj-bh
Copy link
Member Author

shivaraj-bh commented Nov 28, 2024

The above numbers are from omnix repo, I will run them on https://github.com/nammayatri/nammayatri, the result of which I will add to the description of the PR.

Copy link
Member

@srid srid left a comment

Choose a reason for hiding this comment

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

Great

@srid
Copy link
Member

srid commented Nov 28, 2024

The above numbers are from omnix repo, I will run them on https://github.com/nammayatri/nammayatri, the result of which I will add to the description of the PR.

Sure, I'll merge this in the meanwhile.

@srid srid merged commit 75ed489 into main Nov 28, 2024
5 checks passed
@srid srid deleted the yaml-config branch November 28, 2024 01:20
@shivaraj-bh
Copy link
Member Author

shivaraj-bh commented Nov 28, 2024

Using YAML config is 14 times faster than flake config in Nammayatri on x86_64-linux (Updated the PR description).

@shivaraj-bh
Copy link
Member Author

shivaraj-bh commented Nov 28, 2024

On MBP M1 pro it is ~10x faster:

nammayatri on  main via 🐍 v2.7.9 took 4s
❯ nix run github:nixos/nixpkgs/nixpkgs-unstable#hyperfine -- --warmup 10 './with-yaml/bin/om develop --stage pre-shell . && ./with-yaml/bin/om develop --stage post-shell .' './without-yaml/bin/om develop --stage pre-shell . && ./without-yaml/bin/om develop --stage post-shell .'
Benchmark 1: ./with-yaml/bin/om develop --stage pre-shell . && ./with-yaml/bin/om develop --stage post-shell .
  Time (mean ± σ):     185.6 ms ±   3.7 ms    [User: 6.2 ms, System: 2.7 ms]
  Range (min … max):   178.6 ms … 193.8 ms    15 runs

Benchmark 2: ./without-yaml/bin/om develop --stage pre-shell . && ./without-yaml/bin/om develop --stage post-shell .
  Time (mean ± σ):      1.781 s ±  0.058 s    [User: 0.399 s, System: 0.326 s]
  Range (min … max):    1.716 s …  1.922 s    10 runs

Summary
  ./with-yaml/bin/om develop --stage pre-shell . && ./with-yaml/bin/om develop --stage post-shell . ran
    9.59 ± 0.37 times faster than ./without-yaml/bin/om develop --stage pre-shell . && ./without-yaml/bin/om develop --stage post-shell .

@srid
Copy link
Member

srid commented Nov 28, 2024

Clearly an improvement. Let's hope nix config show doesn't become a bottleneck, since that will be run during every direnv refresh/load.

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.

YAML for config
2 participants