Skip to content

Add in-memory caching for directory reads#613

Open
zapdos26 wants to merge 3 commits into
envmodules:mainfrom
zapdos26:fix/readdir-memcache
Open

Add in-memory caching for directory reads#613
zapdos26 wants to merge 3 commits into
envmodules:mainfrom
zapdos26:fix/readdir-memcache

Conversation

@zapdos26
Copy link
Copy Markdown

This pull request introduces an in-memory cache for directory reads in the getFilesInDirectory function to optimize performance by avoiding redundant reads during a single module command invocation. Additionally, a new test has been added to verify that the cache returns consistent results for repeated queries.

Caching improvements:

  • Added an in-memory cache to the getFilesInDirectory function in tcl/main.tcl.in, wrapping the original implementation and storing results for repeated directory queries within a single invocation.

Testing enhancements:

  • Introduced a new test in testsuite/modules.90-avail/025-memcache.exp to confirm that consecutive avail queries on the same module path return consistent results, validating the effectiveness of the cache.

Wrap getFilesInDirectory (C extension or Tcl fallback) with an
in-memory cache keyed by directory path and fetch_dotversion flag.

The cache lives for the duration of a single modulecmd process,
avoiding redundant directory reads when the same directory is
accessed multiple times during module resolution or overlapping
search traversals. This reduces NFS round-trips on systems with
thousands of modulefiles across deep directory structures.

Signed-off-by: zapdos26 <zapdoskid@gmail.com>
Verify that the in-memory getFilesInDirectory cache returns correct
results on repeated queries within a single invocation. Tests
exercise cache population and cache hit paths.

Signed-off-by: zapdos26 <zapdoskid@gmail.com>
@zapdos26 zapdos26 changed the title Fix/readdir memcache Add in-memory chacing for directory reads Feb 17, 2026
@zapdos26 zapdos26 changed the title Add in-memory chacing for directory reads Add in-memory caching for directory reads Feb 17, 2026
…t env(TESTSUITE_MCOOKIE_CHECK) evalhide

Signed-off-by: zapdos26 <zapdoskid@gmail.com>
@smprather
Copy link
Copy Markdown

Adding comments I got from Codex.

Details

  • Medium: the new test does not appear to exercise the cache it is meant to validate. In the PR diff, testsuite/modules.90-avail/025-memcache.exp uses separate testouterr_cmd calls. In this repo, modules-main/
    testsuite/config/base-config.exp:1093 calls modules-main/testsuite/modules.00-init/006-procs.exp:27, which goes through modules-main/testsuite/config/unix.exp:53 and spawns a fresh modulecmd process each
    time. So the per-process in-memory cache is reset between assertions. The test checks output stability, not cache reuse.
  • Low: the cache key in the PR is built as a string concat, "$dir:$fetch_dotversion" in tcl/main.tcl.in:637 from the PR diff. It would be cleaner to use a Tcl list key or nested array to avoid ad hoc key
    encoding.

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.

2 participants