Skip to content

spack load x should load x + runtime deps by default#25732

Closed
haampie wants to merge 1 commit intospack:developfrom
haampie:fix/only-load-top-level-package-by-default
Closed

spack load x should load x + runtime deps by default#25732
haampie wants to merge 1 commit intospack:developfrom
haampie:fix/only-load-top-level-package-by-default

Conversation

@haampie
Copy link
Copy Markdown
Member

@haampie haampie commented Sep 1, 2021

This PR requires #25755 (we need setup_run_environment to be called on dependencies)

The current default of spack load x is to load all dependencies, including build deps of build deps of build deps, which does not make any sense.

The PR changes this into loading x with its runtime deps. That way spack load x behaves equivalent to spack env activate e for an environment e which has x as a root spec.

Also it solves a performance issue: #25669.

Question remains what to do with the --only flag. Should --only=dependencies only load runtime deps? Or should it have the original behavior of loading build deps of build deps of build deps too?

Note that the discussion below about performance is largely irrelevant for this PR; performance is definitely improved, the example given by @tylerjereddy seems to be of a package that has a bunch of run-time deps that should reallly be build/link deps.

change the default of --only=package,dependencies to --only=package,
since it already loads the runtime deps of the package anyways, and why
would you ever want to load the build deps of the run deps of the build
deps of your spec?
@haampie
Copy link
Copy Markdown
Member Author

haampie commented Sep 3, 2021

@becker33 can you comment on this?

The failing test says:

Test that the '-r' option to the load command prepends dependency prefix

but -r is not used in the test, -r has no effect in the command (see #25731), and the test can't hold with just --only=package or --only=dependencies options, you can't specify --only=package,dependencies on the command line, since that's an invalid option according to argparse.

For more context see #25723 (comment)

@tylerjereddy
Copy link
Copy Markdown
Contributor

@haampie Results (minutes:seconds) for four trials of the spack load -r huge_deps_package on one of our nodes are below. As it stands, it still looks like the hacky fast-path is worth vendoring for us if we can't find a way to upstream it. Happy to try other things though, but environments are probably not going to fly in the short-term at least (changeover burden, etc.).

Trial # latest develop with cherry-picks from: #25732 and #25755 latest develop (64407e2) fast path from #25723
1 1:58.68 1:25.20 0:18.10
2 1:32.39 1:27.57 0:03.79
3 1:27.07 1:26.87 0:03.46
4 1:27.19 1:27.12 0:07.14

@haampie
Copy link
Copy Markdown
Member Author

haampie commented Sep 3, 2021

This is confusing... it's strictly slower? It's also strictly doing less work than develop...

For me after spack install py-flake8:

In [1]: from spack.main import SpackCommand
In [2]: load = SpackCommand('load')
In [3]: %timeit load('--sh', 'py-flake8')

Develop: 695 ms ± 4.19 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
#25732 + #25755: 97.4 ms ± 1.39 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

That's 86% faster...

Curiously though I don't see much speedup from the command line:

$ time spack load --sh py-flake8 > /dev/null
real	0m1.427s
$ time spack load --sh py-flake8 > /dev/null
real	0m1.333s

@tylerjereddy
Copy link
Copy Markdown
Contributor

Looks on par with develop for the spack load -r to me. The first trial is sometimes slow for whatever reason (regenerating cache when first connected to the chained instance when I set that up or something?).

Anyway, it was pretty clear for me that I wasn't getting much benefit for the recursive load of ~100 specs with the current situation at least.

@tylerjereddy
Copy link
Copy Markdown
Contributor

tylerjereddy commented Sep 3, 2021

And yeah, we're using command line (tcsh)--so if that command gets called say 100 times, it is roughly equivalent right--you're going to end up at over a minute typically.

@haampie
Copy link
Copy Markdown
Member Author

haampie commented Sep 3, 2021

Right... maybe the packages you're loading specify run type deps but really are only link type deps? (i.e. the dependent does not need <transient dependency prefix>/bin in its path?)

At any rate, I'm confused why load('--sh', 'py-flake8') is fast but spack load --sh py-flake8 almost equally slow. Maybe some caches get destroyed indeed...

@tylerjereddy
Copy link
Copy Markdown
Contributor

tylerjereddy commented Sep 3, 2021

A focus on linking/"including" sounds like a reasonable description of what we have yeah--after all, at least on our end, we really just want CMake to be able to find what spack built and link things in/compile header-only libs, etc., rather than directly executing those dependencies.

Edit: although we do need some binary paths accessible I think--like spack-built Python for example.

@haampie
Copy link
Copy Markdown
Member Author

haampie commented Sep 3, 2021

Okay, so what I've found is: there's 0.6s (!) difference between querying spack load py-flake8 vs spack load /iv36zrg, and further setup_[dependent]_run_environment of python/package.py is rather slow, also we do seemingly redundant calls to set_module_variables_for_package which imho only makes sense for build environments. All in all that gets me to spack load /iv36zrg in 0.5s, which is still slow, but also includes python startup time, which is about 70% of that according to the profiler.

Screenshot from 2021-09-03 19-09-31

So, disambiguate spec is the bulk of the time.

@haampie haampie changed the title make spack load x only load x spack load x should load x + runtime deps by default Sep 17, 2021
@becker33 becker33 self-assigned this May 23, 2022
@tgamblin tgamblin added this to the v0.20.0 milestone Nov 7, 2022
@alalazo alalazo modified the milestones: v0.20.0, v0.21.0 May 3, 2023
@alalazo alalazo removed this from the v0.21.0 milestone Jun 7, 2023
@haampie haampie closed this Dec 17, 2025
@haampie haampie deleted the fix/only-load-top-level-package-by-default branch December 17, 2025 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants