Skip to content

Prune skippable directories based on query path#612

Open
zapdos26 wants to merge 4 commits intoenvmodules:mainfrom
zapdos26:fix/directory-pruning
Open

Prune skippable directories based on query path#612
zapdos26 wants to merge 4 commits intoenvmodules:mainfrom
zapdos26:fix/directory-pruning

Conversation

@zapdos26
Copy link

This pull request adds directory pruning for deep module queries, improving performance by skipping non-matching sibling directories during module discovery. The pruning logic is applied only to specific queries without wildcards, ensuring broad queries still return all results. Comprehensive tests are included to verify correct behavior.

Directory pruning enhancements

  • Added a prunespec argument to findModulesFromDirsAndFiles and findModules to support pruning directories based on the query path, and implemented logic to skip directories that cannot match the query. (tcl/modfind.tcl.in)
  • Modified getModules to enable pruning only for specific deep queries without wildcards, preventing unnecessary directory scans. (tcl/modfind.tcl.in)

Testing improvements

  • Added new modulefiles in a deep directory structure for pruning tests:
    • testsuite/modulefiles.deep/prunetest/cat1/pkg1/1.0
    • testsuite/modulefiles.deep/prunetest/cat1/pkg1/2.0
    • testsuite/modulefiles.deep/prunetest/cat1/pkg2/1.0
    • testsuite/modulefiles.deep/prunetest/cat1/pkg2/2.0
    • testsuite/modulefiles.deep/prunetest/cat2/pkg1/1.0
    • testsuite/modulefiles.deep/prunetest/cat2/pkg1/2.0
    • testsuite/modulefiles.deep/prunetest/cat2/pkg2/1.0
    • testsuite/modulefiles.deep/prunetest/cat2/pkg2/2.0
  • Added a new test script to verify directory pruning behavior for deep queries, including cases with and without wildcards. (testsuite/modules.80-deep/026-pruning-deep.exp)

When a user requests a specific deep module path (e.g. tools/cat15/pkg10/3.0),
the directory walker no longer enters sibling directories that cannot match.
This avoids scanning the entire subtree under a modulepath root.

For a 3000-modulefile tree (tools/category/pkg/version layout):
- module load tools/cat15/pkg10/3.0: 13,007 → 157 syscalls (98.8% reduction)
- module avail tools/cat15/pkg10:    13,005 → 155 syscalls (98.8% reduction)
- module avail tools/cat15:          13,005 → 535 syscalls (95.9% reduction)

Broad queries (module avail, wildcards, --contains) are unaffected.

Signed-off-by: zapdos26 <zapdoskid@gmail.com>
Verify that deep module queries return correct results when directory
pruning skips non-matching sibling directories. Tests cover:
- 3-level and 2-level specific path queries (pruned)
- top-level broad queries (not pruned)
- exact version queries (pruned)
- load through deep path (pruned)
- wildcard queries (not pruned, returns all matches)

Signed-off-by: zapdos26 <zapdoskid@gmail.com>
@zapdos26 zapdos26 changed the title Fix/directory pruning Prune skippable directories based on query path Feb 17, 2026
When pruning non-matching sibling directories during a deep module
query, still read the directory to pick up .modulerc and .version
files. This ensures cross-directory aliases and symbol definitions
are not lost when their containing directory is pruned.

Adds a test for a cross-directory alias defined in cat1/.modulerc
that references a module in cat2/.

Signed-off-by: zapdos26 <zapdoskid@gmail.com>
When the query path contains virtual names (symbols/aliases like 'fld',
'sfld', 'dadj') that don't correspond to real directories, multi-depth
pruning incorrectly skipped sibling directories needed for cross-directory
alias resolution defined in .modulerc files.

Gate pruning on filesystem existence: verify every path component in the
query is a real directory before enabling prunespec. Virtual names fail
the isdirectory check, so pruning is safely disabled. Real deep paths
still get full multi-depth pruning for lstat savings.

Signed-off-by: zapdos26 <zapdoskid@gmail.com>
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.

1 participant